Class: HashTable
Direct Known Subclasses
GTF
Defined Under Namespace
Classes: HashLine
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#load_file
Methods included from Printer
#print, #write
Constructor Details
#initialize(file, opts = {}) ⇒ HashTable
Returns a new instance of HashTable.
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/hash_table.rb', line 126
def initialize(file,opts={})
= opts[:header]
= opts[:skip_header] && opts[:header]
if .is_a? Hash
@types = .values
= .keys
end
create_index opts[:idx]
@lines = []
= opts[:comment]
@types ||= opts[:types]
parse_file(file) if file && File.exists?(file)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/hash_table.rb', line 81
def method_missing sym, *args, &block
if @index[sym]
@index[sym]
else
super sym, *args, &block
end
end
|
Instance Attribute Details
Returns the value of attribute header.
76
77
78
|
# File 'lib/hash_table.rb', line 76
def
end
|
Class Method Details
70
71
72
|
# File 'lib/hash_table.rb', line 70
def
= nil
end
|
67
68
69
|
# File 'lib/hash_table.rb', line 67
def
= true
end
|
.line_class(klass) ⇒ Object
60
61
62
|
# File 'lib/hash_table.rb', line 60
def line_class klass
@line_type = const_get klass.to_s.camel_case
end
|
.line_type ⇒ Object
56
57
58
|
# File 'lib/hash_table.rb', line 56
def line_type
@line_type || HashLine
end
|
64
65
66
|
# File 'lib/hash_table.rb', line 64
def
end
|
Instance Method Details
#[](ind) ⇒ Object
77
78
79
|
# File 'lib/hash_table.rb', line 77
def [](ind)
@lines[ind]
end
|
#add_line(hash) ⇒ Object
141
142
143
144
145
146
147
|
# File 'lib/hash_table.rb', line 141
def add_line hash
if hash.is_a? HashLine
@lines.push hash
else
@lines.push create_line(hash)
end
end
|
#each ⇒ Object
120
121
122
123
124
|
# File 'lib/hash_table.rb', line 120
def each
@lines.each do |l|
yield l
end
end
|
#inspect ⇒ Object
116
117
118
|
# File 'lib/hash_table.rb', line 116
def inspect
"#<#{self.class.name}:#{object_id} @lines=#{@lines.count}>"
end
|
#output(f) ⇒ Object
107
108
109
110
111
112
113
114
|
# File 'lib/hash_table.rb', line 107
def output f
f.puts .join("\t") if
@lines.each do |l|
l = yield l if block_given?
next if !l || l.invalid?
f.puts format_line(l)
end
end
|
#select!(&block) ⇒ Object
95
96
97
|
# File 'lib/hash_table.rb', line 95
def select! &block
@lines.select! &block
end
|
#sort_by!(&block) ⇒ Object
99
100
101
|
# File 'lib/hash_table.rb', line 99
def sort_by! &block
@lines.sort_by! &block
end
|
#sum(col) ⇒ Object
89
90
91
92
93
|
# File 'lib/hash_table.rb', line 89
def sum(col)
inject(0) do |sum,line|
sum += line[col].to_f
end
end
|
103
104
105
|
# File 'lib/hash_table.rb', line 103
def
self.class.
end
|