Class: PxIndexBuilder
- Inherits:
-
Object
- Object
- PxIndexBuilder
- Defined in:
- lib/pxindex-builder.rb
Instance Attribute Summary collapse
-
#to_h ⇒ Object
readonly
Returns the value of attribute to_h.
-
#to_xml ⇒ Object
readonly
Returns the value of attribute to_xml.
Instance Method Summary collapse
-
#initialize(raw_s, ignore = []) ⇒ PxIndexBuilder
constructor
A new instance of PxIndexBuilder.
Constructor Details
#initialize(raw_s, ignore = []) ⇒ PxIndexBuilder
Returns a new instance of PxIndexBuilder.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pxindex-builder.rb', line 14 def initialize(raw_s, ignore=[]) s, _ = RXFHelper.read(raw_s) h = YAML.load(s) words = h.keys.join(' ').split(/ +/).map {|x| x[/\w+/]}.uniq\ #.tap {|x| puts 't: ' + x.inspect} .reject {|x| x.length < 3}\ .reject {|x| ignore.include? x}\ .reject {|x| x.length < 4 and !WordsDotDat.list.include? x.downcase}\ .group_by(&:chr).sort pl = PhraseLookup.new s index = words.map do |letter, list| a = list.map do |w| phrases = pl.q(w) [w, phrases, phrases.map {|x| h[x] }.max] end [letter, a.sort_by(&:last).reverse] end @to_h = h = scan(index) @to_xml = PolyrexBuilder.new(h, parents: %i(entry)).to_xml end |
Instance Attribute Details
#to_h ⇒ Object (readonly)
Returns the value of attribute to_h.
12 13 14 |
# File 'lib/pxindex-builder.rb', line 12 def to_h @to_h end |
#to_xml ⇒ Object (readonly)
Returns the value of attribute to_xml.
12 13 14 |
# File 'lib/pxindex-builder.rb', line 12 def to_xml @to_xml end |