Class: ScrubDb::Strings

Inherits:
Object
  • Object
show all
Defined in:
lib/scrub_db/strings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(criteria = {}) ⇒ Strings

Returns a new instance of Strings.



6
7
8
9
10
# File 'lib/scrub_db/strings.rb', line 6

def initialize(criteria={})
  @empty_criteria = criteria&.empty?
  @filter = ScrubDb::Filter.new(criteria) unless @empty_criteria
  @crmf = CrmFormatter
end

Instance Attribute Details

#empty_criteriaObject

Returns the value of attribute empty_criteria.



4
5
6
# File 'lib/scrub_db/strings.rb', line 4

def empty_criteria
  @empty_criteria
end

#filterObject

Returns the value of attribute filter.



4
5
6
# File 'lib/scrub_db/strings.rb', line 4

def filter
  @filter
end

Instance Method Details

#merge_criteria(hsh) ⇒ Object



38
39
40
# File 'lib/scrub_db/strings.rb', line 38

def merge_criteria(hsh)
  hsh = hsh.merge({ pos_criteria: [], neg_criteria: [] })
end

#scrub_hash(hsh) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/scrub_db/strings.rb', line 43

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_string(string) ⇒ Object



21
22
23
24
25
# File 'lib/scrub_db/strings.rb', line 21

def scrub_proper_string(string)
  hsh = @crmf.format_proper(string)
  hsh = merge_criteria(hsh)
  hsh = scrub_hash(hsh)
end

#scrub_proper_strings(props = []) ⇒ Object



12
13
14
# File 'lib/scrub_db/strings.rb', line 12

def scrub_proper_strings(props=[])
  prop_hashes = props.map! { |str| scrub_proper_string(str) }
end

#scrub_string(string) ⇒ Object



27
28
29
30
31
# File 'lib/scrub_db/strings.rb', line 27

def scrub_string(string)
  hsh = string_to_hash(string)
  hsh = merge_criteria(hsh)
  hsh = scrub_hash(hsh)
end

#scrub_strings(strs = []) ⇒ Object



16
17
18
# File 'lib/scrub_db/strings.rb', line 16

def scrub_strings(strs=[])
  str_hashes = strs.map! { |str| scrub_string(str) }
end

#string_to_hash(string) ⇒ Object



34
35
36
# File 'lib/scrub_db/strings.rb', line 34

def string_to_hash(string)
  hsh = { string: string, pos_criteria: [], neg_criteria: [] }
end