Class: FECForm
- Inherits:
-
Object
show all
- Defined in:
- lib/fechell/forms.rb
Overview
Direct Known Subclasses
FECText, FileHeader, Form24, Form3, ScheduleA, ScheduleB, ScheduleC, ScheduleC1, ScheduleC2, ScheduleD, ScheduleE, ScheduleF
Constant Summary
collapse
- @@schedules =
{}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(schedule, version) ⇒ FECForm
Returns a new instance of FECForm.
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/fechell/forms.rb', line 38
def initialize(schedule, version)
@schedule = schedule
@version = version
@values = {}
@allkeys = []
@data = {}
@options = {}
field(:form_type, ["7.0", "6.4","6.3", "6.2", "6.1","5.3", "5.2", "5.1", "5.00", "3.00"], "FORM TYPE", {:force_upper => true})
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args) ⇒ Object
119
120
121
122
123
|
# File 'lib/fechell/forms.rb', line 119
def method_missing(id, *args)
return send(id) if respond_to?(id)
return @outdata[namespaced(id)][@version] || "" if @allkeys.index(id).nil? == false
raise NoMethodError
end
|
Instance Attribute Details
#schedule ⇒ Object
Returns the value of attribute schedule.
32
33
34
|
# File 'lib/fechell/forms.rb', line 32
def schedule
@schedule
end
|
#values ⇒ Object
Returns the value of attribute values.
34
35
36
|
# File 'lib/fechell/forms.rb', line 34
def values
@values
end
|
#version ⇒ Object
Returns the value of attribute version.
33
34
35
|
# File 'lib/fechell/forms.rb', line 33
def version
@version
end
|
Class Method Details
.available_schedules ⇒ Object
141
142
143
|
# File 'lib/fechell/forms.rb', line 141
def self.available_schedules
@@schedules.keys
end
|
.register(schedule_name, class_name) ⇒ Object
130
131
132
133
|
# File 'lib/fechell/forms.rb', line 130
def self.register(schedule_name, class_name)
@@schedules ||= {}
@@schedules[schedule_name] = class_name
end
|
.schedule_for(schedule, version, values) ⇒ Object
135
136
137
138
139
|
# File 'lib/fechell/forms.rb', line 135
def self.schedule_for(schedule,version,values)
f = @@schedules[schedule.to_sym].send(:new, schedule,version)
f.parse(values)
f
end
|
Instance Method Details
#as_activerecord(model) ⇒ Object
125
126
127
128
|
# File 'lib/fechell/forms.rb', line 125
def as_activerecord(model)
ar = model.send(:new, as_hash())
ar
end
|
#as_hash ⇒ Object
111
112
113
114
115
116
117
|
# File 'lib/fechell/forms.rb', line 111
def as_hash()
h = {}
@allkeys.each do |key|
h[key] = @outdata[namespaced(key)][@version]
end
h
end
|
#field(key, fversion, value, options = {}) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/fechell/forms.rb', line 50
def field(key, fversion, value,options = {} )
@values[namespaced(key)] ||= {}
@options[namespaced(key)] ||= {}
@outdata = {}
[fversion].flatten.each do |fec_version|
@values[namespaced(key)][fec_version] = value
@options[namespaced(key)][fec_version] = options
end
@allkeys << key
@allkeys.uniq!
end
|
#ordered_keys ⇒ Object
107
108
109
|
# File 'lib/fechell/forms.rb', line 107
def ordered_keys()
@allkeys
end
|
#parse(line) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/fechell/forms.rb', line 68
def parse(line)
line.each do |k,v|
@data[k] = v
end
@allkeys.each do |key|
dirty = false
keyoptions = @options[namespaced(key)][@version] || {}
value = @data[@values[namespaced(key)][@version]]
@outdata[namespaced(key)] ||= {}
if keyoptions[:default].nil? == false
value = keyoptions[:default]
end
next if value.nil? == true
if keyoptions[:force_upper] == true
value = value.to_s.upcase
elsif keyoptions[:split] == true
splitchar = keyoptions[:split_char] || '^'
splitindex = keyoptions[:split_index] || 0
parts = value.split(splitchar)
if parts.length < splitindex
value = ''
else
value = parts[splitindex]
end
end
@outdata[namespaced(key)][@version] = value
end
end
|