Class: ReVIEW::Catalog

Inherits:
Object show all
Defined in:
lib/review/catalog.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Catalog

Returns a new instance of Catalog.



5
6
7
8
9
10
11
12
# File 'lib/review/catalog.rb', line 5

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

Instance Method Details

#appendixObject



42
43
44
45
# File 'lib/review/catalog.rb', line 42

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

#chapsObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/review/catalog.rb', line 19

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

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

#partsObject



31
32
33
34
35
# File 'lib/review/catalog.rb', line 31

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

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

#parts_with_chapsObject



37
38
39
40
# File 'lib/review/catalog.rb', line 37

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

#postdefObject



47
48
49
50
# File 'lib/review/catalog.rb', line 47

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

#predefObject



14
15
16
17
# File 'lib/review/catalog.rb', line 14

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