Class: Fech::DefaultTranslations

Inherits:
Object
  • Object
show all
Defined in:
lib/fech/default_translations.rb

Overview

Stores sets of build-in translations that can be mixed in to a Fech::Filing. Contains functions that accept a Translator, and add arbitrary translations to it. The public function names should correspond to the key used to mix it in.

filing = Fech::Filing.new(XXXXXX, :translate => [:names, :dates])

Constant Summary collapse

NAME_BITS =

The five bits that make up a name, and their labels in the People gem

[:prefix, :first_name, :middle_name, :last_name, :suffix]
PEOPLE_BITS =
[:title, :first, :middle, :last, :suffix]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(translator) ⇒ DefaultTranslations

Returns a new instance of DefaultTranslations.



16
17
18
# File 'lib/fech/default_translations.rb', line 16

def initialize(translator)
  @t = translator
end

Instance Attribute Details

#tObject (readonly)

Returns the value of attribute t.



14
15
16
# File 'lib/fech/default_translations.rb', line 14

def t
  @t
end

Instance Method Details

#datesObject

Converts everything that looks like an FEC-formatted date to a native Ruby Date object.



67
68
69
70
71
72
73
# File 'lib/fech/default_translations.rb', line 67

def dates
  # only convert fields whose name is date* or *_date*
  # lots of other things might be 8 digits, and we have to exclude eg 'candidate'
  t.convert :field => /(^|_)date/ do |value|
    Date.parse(value) rescue value
  end
end

#namesObject

Splits composite names into its component parts, and combines those parts into composites where appropriate. Assumes that the canonical names of the fields follow the pattern:

* FIELD_name         - "Mr. John Charles Smith Sr."
* FIELD_prefix       - "Mr."
* FIELD_first_name   - "John"
* FIELD_middle_name  - "Charles"
* FIELD_last_name    - "Smith"
* FIELD_suffix       - "Sr."


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fech/default_translations.rb', line 29

def names
  
  # COMBINE split names into composite names for these rows
  composites = [
    {:row => :sa,     :version => /^[6-8]/,   :field => [:contributor, :donor_candidate]},
    {:row => :sb,     :version => /^[6-8]/,   :field => [:payee, :beneficiary_candidate]},
    {:row => :sc,     :version => /^[6-8]/,   :field => [:lender, :lender_candidate]},
    {:row => :sc1,    :version => /^[6-8]/,   :field => [:treasurer, :authorized]},
    {:row => :sc2,    :version => /^[6-8]/,   :field => :guarantor},
    {:row => :sd,     :version => /^[6-8]/,   :field => :creditor},
    {:row => :se,     :version => /^[6-8]/,   :field => [:payee, :candidate]},
    {:row => :sf,     :version => /^[6-8]/,   :field => [:payee, :payee_candidate]},
    {:row => :f3p,    :version => /^[6-8]/,   :field => :treasurer},
    {:row => :f3p31,  :version => /^[6-8]/,   :field => :contributor},
  ]
  # SPLIT composite names into component parts for these rows
  components = [
    {:row => :sa,     :version => /^3|(5.0)/, :field => :contributor},
    {:row => :sa,     :version => /^[3-5]/,   :field => :donor_candidate},
    {:row => :sb,     :version => /^3|(5.0)/, :field => :payee},
    {:row => :sb,     :version => /^[3-5]/,   :field => :beneficiary_candidate},
    {:row => :sc,     :version => /^[3-5]/,   :field => [:lender, :lender_candidate]},
    {:row => :sc1,    :version => /^[3-5]/,   :field => [:treasurer, :authorized]},
    {:row => :sc2,    :version => /^[3-5]/,   :field => :guarantor},
    {:row => :sd,     :version => /^[3-5]/,   :field => :creditor},
    {:row => :se,     :version => /^[3-5]/,   :field => [:payee, :cadidate]},
    {:row => :sf,     :version => /^[3-5]/,   :field => [:payee, :payee_candidate]},
    {:row => :f3p,    :version => /^[3-5]/,   :field => :treasurer},
    {:row => :f3p31,  :version => /^[3-5]/,   :field => :contributor},
  ]
  
  composites.each { |c| combine_components_into_name(c) }
  components.each { |c| split_name_into_components(c) }
  
end