Sha256: 0b56fc62b2869a57ba32b6956e739d914dc09575dff12a64d7317d4b30b1e129

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

require 'yaml'

module ReVIEW
  class Catalog
    def initialize(file)
      if file.respond_to? :read
        @yaml = YAML.load(file.read)
      else ## as Object
        @yaml = file
      end
      @yaml ||= {}
    end

    def predef
      return "" unless @yaml["PREDEF"]
      @yaml["PREDEF"].join("\n")
    end

    def chaps
      return "" unless @yaml["CHAPS"]

      @yaml["CHAPS"].map {|entry|
        if entry.is_a? String
          entry
        elsif entry.is_a? Hash
          entry.values # chaps in a part
        end
      }.flatten.join("\n")
    end

    def parts
      return "" unless @yaml["CHAPS"]

      @yaml["CHAPS"].map {|entry|
        if entry.is_a? Hash
          entry.keys
        end
      }.flatten.compact.join("\n")
    end

    def parts_with_chaps
      return "" unless @yaml["CHAPS"]
      @yaml["CHAPS"].flatten.compact
    end

    def appendix
      return "" unless @yaml["APPENDIX"]
      @yaml["APPENDIX"].join("\n")
    end

    def postdef
      return "" unless @yaml["POSTDEF"]
      @yaml["POSTDEF"].join("\n")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
review-2.3.0 lib/review/catalog.rb
review-2.2.0 lib/review/catalog.rb