Class: ScrubDb::Strings
- Inherits:
-
Object
- Object
- ScrubDb::Strings
- Defined in:
- lib/scrub_db/strings.rb
Instance Attribute Summary collapse
-
#empty_criteria ⇒ Object
Returns the value of attribute empty_criteria.
-
#filter ⇒ Object
Returns the value of attribute filter.
Instance Method Summary collapse
-
#initialize(criteria = {}) ⇒ Strings
constructor
A new instance of Strings.
- #merge_criteria(hashes) ⇒ Object
- #scrub_hash(hsh) ⇒ Object
- #scrub_proper_strings(props = []) ⇒ Object
- #scrub_strings(strings = []) ⇒ Object
- #strings_to_hashes(strings) ⇒ Object
Constructor Details
Instance Attribute Details
#empty_criteria ⇒ Object
Returns the value of attribute empty_criteria.
5 6 7 |
# File 'lib/scrub_db/strings.rb', line 5 def empty_criteria @empty_criteria end |
#filter ⇒ Object
Returns the value of attribute filter.
5 6 7 |
# File 'lib/scrub_db/strings.rb', line 5 def filter @filter end |
Instance Method Details
#merge_criteria(hashes) ⇒ Object
28 29 30 31 32 |
# File 'lib/scrub_db/strings.rb', line 28 def merge_criteria(hashes) hashes.map do |hsh| hsh.merge({ pos_criteria: [], neg_criteria: [] }) end end |
#scrub_hash(hsh) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/scrub_db/strings.rb', line 34 def scrub_hash(hsh) str = hsh[:string] prop = hsh[:proper_f] if str.present? hsh = @filter.scrub_oa(hsh, str, 'neg_criteria', 'include') hsh = @filter.scrub_oa(hsh, str, 'pos_criteria', 'include') end if prop.present? hsh = @filter.scrub_oa(hsh, prop, 'neg_criteria', 'include') hsh = @filter.scrub_oa(hsh, prop, 'pos_criteria', 'include') end hsh end |
#scrub_proper_strings(props = []) ⇒ Object
12 13 14 15 16 |
# File 'lib/scrub_db/strings.rb', line 12 def scrub_proper_strings(props=[]) prop_hashes = CrmFormatter.format_propers(props) prop_hashes = merge_criteria(prop_hashes) prop_hashes.map! { |prop_hsh| scrub_hash(prop_hsh) } end |
#scrub_strings(strings = []) ⇒ Object
18 19 20 21 22 |
# File 'lib/scrub_db/strings.rb', line 18 def scrub_strings(strings=[]) str_hashes = strings_to_hashes(strings) str_hashes = merge_criteria(str_hashes) str_hashes.map! { |str_hsh| scrub_hash(str_hsh) } end |
#strings_to_hashes(strings) ⇒ Object
24 25 26 |
# File 'lib/scrub_db/strings.rb', line 24 def strings_to_hashes(strings) str_hashes = strings.map { |str| { string: str } } end |