Sha256: 7ab86975b31f1e94b3277853ee775addc37a5b61d13eaaf1b6a87894d6656aea

Contents?: true

Size: 1.01 KB

Versions: 14

Compression:

Stored size: 1.01 KB

Contents

require 'yaml'

module ReVIEW
  class Catalog
    def initialize(file)
      @yaml = YAML.load(file.read)
      @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.reject{|entry| entry.nil?}.join("\n")
    end

    def parts_with_chaps
      return "" unless @yaml["CHAPS"]
      @yaml["CHAPS"].flatten.reject{|entry| entry.nil?}
    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

14 entries across 14 versions & 2 rubygems

Version Path
review-1.7.2 lib/review/catalog.rb
review-1.7.1 lib/review/catalog.rb
review-peg-0.2.2 lib/review/catalog.rb
review-peg-0.2.1 lib/review/catalog.rb
review-peg-0.2.0 lib/review/catalog.rb
review-peg-0.1.3 lib/review/catalog.rb
review-peg-0.1.2 lib/review/catalog.rb
review-peg-0.1.1 lib/review/catalog.rb
review-peg-0.1.0 lib/review/catalog.rb
review-1.7.0 lib/review/catalog.rb
review-1.6.0 lib/review/catalog.rb
review-2.0.0.beta1 lib/review/catalog.rb
review-1.5.0 lib/review/catalog.rb
review-1.4.0 lib/review/catalog.rb