Class: KjDotXml
- Inherits:
-
Object
- Object
- KjDotXml
- Defined in:
- lib/kjdotxml.rb
Instance Attribute Summary collapse
-
#booklist ⇒ Object
readonly
Returns the value of attribute booklist.
Instance Method Summary collapse
- #book(s) ⇒ Object
- #books(ref = nil) ⇒ Object
-
#initialize(title = nil, debug: false) ⇒ KjDotXml
constructor
A new instance of KjDotXml.
- #to_doc ⇒ Object
- #verses(s) ⇒ Object
Constructor Details
Instance Attribute Details
#booklist ⇒ Object (readonly)
Returns the value of attribute booklist.
84 85 86 |
# File 'lib/kjdotxml.rb', line 84 def booklist @booklist end |
Instance Method Details
#book(s) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/kjdotxml.rb', line 95 def book(s) filename = s.downcase.gsub(/\s/,'-') + '.xml' filepath = File.join(File.dirname(__FILE__), '..', 'xml', filename) if File.exists? filepath then contents = File.read(filepath) @doc = Rexle.new(contents) else raise KjDotXmlError, 'book not found' end end |
#books(ref = nil) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/kjdotxml.rb', line 111 def books(ref=nil) return @booklist.map {|x| books(x) } unless ref index = ref.to_s[/^\d+$/] ? (ref.to_i - 1) : find_book(ref.downcase) puts 'index: ' + index.inspect if @debug title = @booklist[index] end |
#to_doc ⇒ Object
151 152 153 |
# File 'lib/kjdotxml.rb', line 151 def to_doc() @doc end |
#verses(s) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/kjdotxml.rb', line 123 def verses(s) r = s.match(/(?<book>\w+)\s+(?<chapter>\d+)[,\:]?\s*(?<verses>.*)/) verses2 = r[:verses] =~ /(?:\.\.|,|-)/ ? Range.new(*r[:verses]\ .split(/(?:\.\.|,|-)/).map(&:to_i)).to_a : r[:verses] puts 'r[:book]: ' + r[:book].inspect if @debug doc = book(books(r[:book])) puts 'verses2: ' + verses2.inspect if @debug if verses2.is_a? String then [ doc.root.element("chapter[@no='#{r[:chapter]}']/verse" + "[@no='#{verses2}']") ] elsif verses2.is_a? Array verses2.map do |verse| doc.root.element("chapter[@no='#{r[:chapter]}']/verse[@no='#{verse}']") end end end |