ruby-factual 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.md +15 -3
  2. data/lib/factual.rb +12 -9
  3. metadata +36 -5
data/README.md CHANGED
@@ -1,16 +1,28 @@
1
1
  ## Sample Usage
2
+
3
+ A block of code is worth a thousand words.
2
4
  > require 'rubygems'
3
5
  > gem 'ruby-factual'
4
6
  > require 'factual'
5
7
  >
6
8
  > api = Factual::Api.new(:api_key => "<YOUR_FACTUAL_API_KEY>", :version => 2)
7
9
  >
10
+ > # get table and its metadata
11
+ > # table metadata: name, description, rating, source, creator, created_at,
12
+ > # updated_at, total_row_count, geo_enabled, downloadable,
13
+ > # fields (array of hash)
8
14
  > table = api.get_table("g9R1u2")
9
- > puts table.name
15
+ > puts table.name, table.creator
10
16
  >
11
- > table.filter(:two_letter_abbrev => "CA").sort(:state => -1)each_row do |state_info|
17
+ > # read rows after filtering and sorting
18
+ > table.filter(:two_letter_abbrev => "CA").sort(:state => -1).each_row do |state_info|
19
+ >
20
+ > # read facts
21
+ > # fact attributes: value, subject_key, field_ref, field (hash)
12
22
  > fact = state_info["state"]
13
- > puts fact.value
23
+ > puts fact.value, fact.subject_key
24
+ >
25
+ > # write facts
14
26
  > if fact.input("Kalifornia", :source => "source", :comment => "comment")
15
27
  > puts "inputted"
16
28
  > end
data/lib/factual.rb CHANGED
@@ -18,14 +18,17 @@ module Factual
18
18
 
19
19
  class Table
20
20
  attr_accessor :name, :description, :rating, :source, :creator, :total_row_count, :created_at, :updated_at, :fields, :geo_enabled, :downloadable
21
+ attr_accessor :key, :adapter
22
+
21
23
  def initialize(table_key, adapter)
22
24
  @table_key = table_key
23
- @adapter = adapter
24
- @schema = adapter.schema(@table_key)
25
+ @adapter = adapter
26
+ @schema = adapter.schema(@table_key)
27
+ @key = table_key
25
28
 
26
29
  [:name, :description, :rating, :source, :creator, :total_row_count, :created_at, :updated_at, :fields, :geo_enabled, :downloadable].each do |attr|
27
- key = camelize(attr)
28
- self.send("#{attr}=", @schema[key])
30
+ k = camelize(attr)
31
+ self.send("#{attr}=", @schema[k])
29
32
  end
30
33
 
31
34
  @fields.each do |f|
@@ -59,7 +62,7 @@ module Factual
59
62
 
60
63
  # TODO iterator
61
64
  rows.each do |row_data|
62
- row = Row.new(@adapter, @table_key, @fields, row_data)
65
+ row = Row.new(self, row_data)
63
66
  yield(row) if block_given?
64
67
  end
65
68
  end
@@ -81,11 +84,11 @@ module Factual
81
84
  class Row
82
85
  attr_accessor :subject_key, :subject
83
86
 
84
- def initialize(adapter, table_key, fields, row_data)
87
+ def initialize(table, row_data)
85
88
  @subject_key = row_data[0]
86
- @fields = fields
87
- @table_key = table_key
88
- @adapter = adapter
89
+ @fields = table.fields
90
+ @table_key = table.key
91
+ @adapter = table.adapter
89
92
 
90
93
  @subject = []
91
94
  @fields.each_with_index do |f, idx|
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-factual
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Forrest Cao
@@ -17,8 +17,39 @@ cert_chain: []
17
17
 
18
18
  date: 2010-09-14 00:00:00 +08:00
19
19
  default_executable:
20
- dependencies: []
21
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: curb
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 27
30
+ segments:
31
+ - 0
32
+ - 3
33
+ - 4
34
+ version: 0.3.4
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: json
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 31
46
+ segments:
47
+ - 1
48
+ - 2
49
+ - 0
50
+ version: 1.2.0
51
+ type: :runtime
52
+ version_requirements: *id002
22
53
  description: ""
23
54
  email: forrest@factual.com
24
55
  executables: []