Module: FeatureDuplicator
- Included in:
- PfrpgReaders::MiscReader
- Defined in:
- lib/pfrpg_readers/feature_duplicator.rb
Instance Method Summary collapse
- #dupe_words ⇒ Object
-
#filter_duplicates(features) ⇒ Object
filter things with multiple bonuses, like sneak attack and channel energy.
-
#parse_number(description) ⇒ Object
of the form, ‘Sneak Attack (10d6)’.
- #smallest(features, phrase) ⇒ Object
Instance Method Details
#dupe_words ⇒ Object
3 4 5 |
# File 'lib/pfrpg_readers/feature_duplicator.rb', line 3 def dupe_words ['Sneak Attack', 'Channel Energy', 'Damage Reduction', 'Trap Sense'] end |
#filter_duplicates(features) ⇒ Object
filter things with multiple bonuses, like sneak attack and channel energy
8 9 10 11 12 13 |
# File 'lib/pfrpg_readers/feature_duplicator.rb', line 8 def filter_duplicates(features) dupe_words.each do |w| features = features - smallest(features, w) end features end |
#parse_number(description) ⇒ Object
of the form, ‘Sneak Attack (10d6)’
23 24 25 |
# File 'lib/pfrpg_readers/feature_duplicator.rb', line 23 def parse_number(description) (description.split('d6')[0].split(' ').last.split('(')[1]).to_i end |
#smallest(features, phrase) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/pfrpg_readers/feature_duplicator.rb', line 15 def smallest(features, phrase) smallest = features.select { |x| x.name[phrase] != nil } return [] if (smallest.empty? || smallest.size == 1) smallest.sort_by! { |x| parse_number(x.name) } smallest[0..smallest.size-2] end |