Class: OpenTaxFormFiller::Pjsons

Inherits:
Object
  • Object
show all
Extended by:
Assertions::ClassMethods, GenericFiles::Assertions::ClassMethods, GenericFiles::ClassMethods, NoDB::ClassMethods
Includes:
Assertions, GenericFiles, GenericFiles::Assertions, NoDB, Constants, Examples
Defined in:
app/models/open_tax_form_filler.rb

Overview

Transforms

Defined Under Namespace

Modules: Constants, Examples

Constant Summary

Constants included from ColumnGroup::ClassMethods

ColumnGroup::ClassMethods::History_columns

Constants included from GenericGrep::ClassMethods

GenericGrep::ClassMethods::ASSOCIATION_MACRO_LETTERS, GenericGrep::ClassMethods::ASSOCIATION_MACRO_PATTERN

Constants included from Examples

Examples::All, Examples::Simple_acquisition

Constants included from Constants

Constants::Data_source_directory, Constants::End_regexp, Constants::Field_name_regexp, Constants::Full_regexp_array, Constants::Last_field_regexp, Constants::Open_tax_filler_directory, Constants::Path_regexp, Constants::Record_separator, Constants::Start_regexp

Constants included from Constants

Constants::Data_source_directory, Constants::Default_tax_year

Constants included from NoDB

NoDB::DEFAULT_TYPE

Constants included from GenericTableAssociation::Examples

GenericTableAssociation::Examples::First_stream_method

Instance Attribute Summary

Attributes included from NoDB

#attributes

Class Method Summary collapse

Methods included from GenericFiles::Assertions::ClassMethods

assert_post_conditions, assert_pre_conditions

Methods included from GenericFiles::ClassMethods

all_initialize, dump_sql_to_file, raw_acquisitions, table_name?

Methods included from NoDB::ClassMethods

column_symbols, data_source_yaml, default_names, dump, get_field_names, insert_sql, table_class, table_name

Methods included from Generic_Table::ClassMethods

#is_active_record_method?, #model_file_name, #nesting, #one_pass_statistics, #sample, #sample_burst

Methods included from ColumnGroup::ClassMethods

#attribute_ddl, #attribute_rails_type, #attribute_ruby_type, #candidate_logical_keys_from_indexes, #categorical?, #column_symbols, #default_logical_primary_key, #defaulted_primary_logical_key?, #history_type?, #is_logical_primary_key?, #logical_attributes, #logical_primary_key, #logical_primary_key_recursive, #numerical?, #probably_categorical?, #probably_numerical?, #sequential_id?

Methods included from GenericGrep::ClassMethods

#all_associations, #association_grep, #association_grep_pattern, #association_macro_type, #association_type, #belongs_to_association?, #grep_all_associations_command, #grep_command, #has_many_association?, #has_one_association?, #model_grep, #model_grep_command

Methods included from GenericTableHtml::ClassMethods

#column_order, #header_html, #table_html

Methods included from GenericFiles::Assertions

#assert_post_conditions, #assert_pre_conditions

Methods included from NoDB

#[], #[]=, #clone, #each_pair, #has_key?, #initialize, #insert_sql, #keys, #table_class, #table_name

Methods included from Generic_Table

activeRecordTableNotCreatedYet?, classDefiniton, classReference, class_of_name, eval_constant, is_ActiveRecord_table?, is_generic_table?, is_generic_table_name?, is_table?, rails_MVC_class?, rubyClassName, table_exists?

Methods included from GenericTableAssociation

#associated_foreign_key_records, #associated_to_s, #association_class, #association_has_data, #association_state, #foreign_key_points_to_me?, #foreign_key_to_association, #foreign_key_value, #logical_primary_key_recursive_value, #logical_primary_key_value, #name_to_association

Methods included from GenericTableAssociation::Assertions::ClassMethods

#assert_foreign_keys_not_nil, #assert_invariant, #assert_post_conditions, #assert_pre_conditions

Methods included from GenericTableAssociation::Assertions

#assert_associated_foreign_key, #assert_associated_foreign_key_name, #assert_association, #assert_association_methods, #assert_association_to_many, #assert_association_to_one, #assert_foreign_key_association_names, #assert_foreign_key_name, #assert_foreign_key_not_nil, #assert_foreign_keys_not_nil, #assert_invariant, #assert_post_conditions, #assert_pre_conditions

Methods included from GenericTableHtml

#column_html, #rails_route, #row_html

Class Method Details

.allObject

parse


160
161
162
# File 'app/models/open_tax_form_filler.rb', line 160

def self.all
	All
end

.coarse_filterObject

subset_regexp


200
201
202
203
204
205
206
# File 'app/models/open_tax_form_filler.rb', line 200

def self.coarse_filter
	raw_acquisitions.select do |acquisition|
		Full_regexp_array.first do |rs|
			/#{rs}/.match(acquisition)
		end #first
	end #select
end

.full_regexp_arrayObject

input_file_names


136
137
138
# File 'app/models/open_tax_form_filler.rb', line 136

def self.full_regexp_array
	Full_regexp_array
end

.input_file_namesObject


133
134
135
# File 'app/models/open_tax_form_filler.rb', line 133

def self.input_file_names
	"#{Open_tax_filler_directory}/field_dump/Federal/f*.pjson"
end

.leftmost_match(regexp_array, acquisition) ⇒ Object

match_regexp_array


179
180
181
182
183
# File 'app/models/open_tax_form_filler.rb', line 179

def self.leftmost_match(regexp_array, acquisition)
	[0..regexp_array.size-1].times.find do |i|
		match_regexp_array(regexp_array[0..i], acquisition)
	end #find
end

.match_regexp_array(combination_indices, acquisition) ⇒ Object

array of indices to match nil value means need insertion of any characters


165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'app/models/open_tax_form_filler.rb', line 165

def self.match_regexp_array(combination_indices, acquisition)
	rest=acquisition
	regexp_string=Full_regexp_array[combination_indices[0]]
	combination_indices.each_cons(2) do |pair|
		if pair[0]+1==pair[1] then # consecutive match
			added_regexp=Full_regexp_array[pair[1]]
		else #mismatch deleted
			added_regexp="(?<error_#{pair[0]}>.*)"
		end #if
		regexp_string+=added_regexp
	end #each_cons
	regexp=Regexp.new(regexp_string)
	matchData=regexp.match(acquisition)
end

.parseObject

returns array of hashes


140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'app/models/open_tax_form_filler.rb', line 140

def self.parse 
	array_of_hashes=[]
	coarse= raw_acquisitions.map do |acquisition|
		begin
		hash={}
		regexp=Regexp.new(Full_regexp_array.join)
		matchData=regexp.match(acquisition)
		if matchData then
			matchData.names.map do |n|
				hash[n.to_sym]=matchData[n]
			end #map
			acquisition=matchData.post_match
		else
			acquisition=nil
			end #if
		array_of_hashes << hash
		end until (acquisition.nil?) | (acquisition.empty?) | (acquisition.size==0)
		array_of_hashes
	end.flatten #map
end

.reverse_array_match(regexp_array, acquisition) ⇒ Object

leftmost_match


184
185
186
187
188
# File 'app/models/open_tax_form_filler.rb', line 184

def self.reverse_array_match(regexp_array, acquisition)
	Array.new(regexp_array.size){|i| regexp_array.size-i}.find do |i|
		match_regexp_array(regexp_array[i..-1], acquisition)
	end #find
end

.subset_regexp(size) ⇒ Object

reverse_array_match


189
190
191
192
193
194
195
196
197
198
199
# File 'app/models/open_tax_form_filler.rb', line 189

def self.subset_regexp(size)
	longest=Full_regexp_array.size
	Full_regexp_array.combination(longest) do |c|
		raw_acquisitions.map do |line|
			Regexp.new(c.join).match(line)
		end #map
	end #combinations
	Full_regexp_array.map do |rs|
		/#{rs}/
	end #map
end