Class: Factual::Row
- Inherits:
-
Object
- Object
- Factual::Row
- Defined in:
- lib/factual.rb
Overview
This class holds the subject_key, subject (in array) and facts (Factual::Fact objects) of a Factual Subject.
The subject_key and subject array can be accessable directly from attributes, and you can get a fact by row[field_ref]
.
Instance Attribute Summary collapse
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
-
#subject_key ⇒ Object
readonly
Returns the value of attribute subject_key.
Instance Method Summary collapse
-
#[](field_ref) ⇒ Object
Get a Factual::Fact object by field_ref.
-
#initialize(table, subject_key, row_data = []) ⇒ Row
constructor
:nodoc:.
Constructor Details
#initialize(table, subject_key, row_data = []) ⇒ Row
:nodoc:
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/factual.rb', line 254 def initialize(table, subject_key, row_data=[]) # :nodoc: @subject_key = subject_key @table = table @fields = @table.fields @table_key = @table.key @adapter = @table.adapter if row_data.empty? && subject_key single_row_mode = true row_data = @adapter.read_row(@table_key, subject_key) end idx_offset = single_row_mode ? 1 : 0; @subject = [] @fields.each_with_index do |f, idx| next unless f["isPrimary"] @subject << row_data[idx + idx_offset] end @facts_hash = {} @fields.each_with_index do |f, idx| next if f["isPrimary"] @facts_hash[f["field_ref"]] = Fact.new(@table, @subject_key, f, row_data[idx + idx_offset]) end end |
Instance Attribute Details
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
252 253 254 |
# File 'lib/factual.rb', line 252 def subject @subject end |
#subject_key ⇒ Object (readonly)
Returns the value of attribute subject_key.
252 253 254 |
# File 'lib/factual.rb', line 252 def subject_key @subject_key end |
Instance Method Details
#[](field_ref) ⇒ Object
Get a Factual::Fact object by field_ref
Sample:
city_info = table.filter(:state => 'CA').find_one
city_info['city_name']
287 288 289 |
# File 'lib/factual.rb', line 287 def [](field_ref) @facts_hash[field_ref] end |