Class: ReVIEW::Catalog
Instance Method Summary collapse
- #appendix ⇒ Object
- #chaps ⇒ Object
-
#initialize(file) ⇒ Catalog
constructor
A new instance of Catalog.
- #parts ⇒ Object
- #parts_with_chaps ⇒ Object
- #postdef ⇒ Object
- #predef ⇒ Object
- #replace_part(old_name, new_name) ⇒ Object
- #to_s ⇒ Object
- #validate!(config, basedir) ⇒ Object
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.safe_load(file.read, [Date]) else ## as Object @yaml = file end @yaml ||= {} end |
Instance Method Details
#appendix ⇒ Object
56 57 58 |
# File 'lib/review/catalog.rb', line 56 def appendix @yaml['APPENDIX'] || [] end |
#chaps ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/review/catalog.rb', line 18 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 end |
#parts ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/review/catalog.rb', line 30 def parts return [] unless @yaml['CHAPS'] part_list = @yaml['CHAPS'].map do |entry| if entry.is_a?(Hash) entry.keys end end part_list.flatten.compact end |
#parts_with_chaps ⇒ Object
51 52 53 54 |
# File 'lib/review/catalog.rb', line 51 def parts_with_chaps return [] unless @yaml['CHAPS'] @yaml['CHAPS'].flatten.compact end |
#postdef ⇒ Object
60 61 62 |
# File 'lib/review/catalog.rb', line 60 def postdef @yaml['POSTDEF'] || [] end |
#predef ⇒ Object
14 15 16 |
# File 'lib/review/catalog.rb', line 14 def predef @yaml['PREDEF'] || [] end |
#replace_part(old_name, new_name) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/review/catalog.rb', line 42 def replace_part(old_name, new_name) @yaml['CHAPS'].map! do |e| if e.is_a?(Hash) and (e.keys.first == old_name) e = { new_name => e.values.first } end e end end |
#to_s ⇒ Object
64 65 66 |
# File 'lib/review/catalog.rb', line 64 def to_s YAML.dump(@yaml).gsub(/\A---\n/, '') # remove yaml header end |
#validate!(config, basedir) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/review/catalog.rb', line 68 def validate!(config, basedir) filenames = [] if predef.present? filenames.concat(predef) end parts_with_chaps.each do |chap| if chap.is_a?(Hash) chap.each_key do |part| if File.extname(part) == '.re' filenames.push(part) end end filenames.concat(chap.values.flatten) else filenames.push(chap) end end if appendix.present? filenames.concat(appendix) end if postdef.present? filenames.concat(postdef) end filenames.each do |filename| refile = File.join(basedir, config['contentdir'], filename) unless File.exist?(refile) raise FileNotFound, "file not found in catalog.yml: #{refile}" end end end |