simple_time_series 0.1.6 → 0.1.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96fc69681d3c929e6f16e8f162be2fc246128eed
4
- data.tar.gz: 2737be6e56ae082830a0273e76b09663ac94d713
3
+ metadata.gz: ea71f33d9379194751d0185a8c80785f6f107e75
4
+ data.tar.gz: 4c0cfefa649209183c53a447e4a1421c77ce3429
5
5
  SHA512:
6
- metadata.gz: 3b3d87226d74112ebf4c4a2650f57e9340a3a27e1a1de61347be8096606009e5b70610d74f17ec72f5fa072dd86901c6d5031c58a115e41507d659e4e19f4f03
7
- data.tar.gz: 01753f203de51d3b6f321cd1c010a931f4764fd657986ecff98c5c4b05c487c1f5bc738f84234e8b2bba103301549347b3c35dae06254d5b98aa3b2d657c4b11
6
+ metadata.gz: 91c7b8b6e4d342656d125b94270b9365c2a6bab5c5e79ae9c8963d015dcd2e49212e26a6db242fa800fe5c434197c5c768d7d08e9dbbdd9c88d4b33d6ab5d16b
7
+ data.tar.gz: 7dc09d39e91eb4e636bd70690164f10357ab5ec2d30916e63e6a2ea20dffe4802c19ebb3af20a9f19b446d6f9561ed183420adbbd83da4f4d4bea3ca9916bb86
data/README.md CHANGED
@@ -42,14 +42,36 @@ This is sufficient to package up your data into a SimpleTimeSeries object:
42
42
  'miles' => miles,
43
43
  'tasks_done' => tasks_done})
44
44
 
45
- If your input data is strings but should be converted into numeric, you can call #to_num on it and it will be converted to an array of integers (where possible) or floats:
45
+ If a data array contains strings that should be converted to numeric values, you can call #to_num on the data array and its values will be converted to integers (where possible) or floats:
46
46
 
47
47
  donuts = ["6", "0", "2", "4.5", "1.5", "0", "9"]
48
48
  new_data = SimpleTimeSeries.new(:time_vars => {'dates' => dates},
49
49
  :data_vars => {'donuts' => donuts.to_num})
50
50
  new_data.current('donuts') #returns [6, 0, 2, 4.5, 1.5, 0, 9]
51
51
 
52
- You can now easily access the value of any data variable for any value of one of your time variables via xxx_on methods created for each of your data_vars (here called 'pizzas_on,' 'miles_on' and 'tasks_done_on'):
52
+ You can, optionally, pass a hash of :attribs into SimpleTimeSeries.new with additional attributes for each of your time_vars and data_vars. You can call these attributes anything you want and then query their values later. For example, we can associate each data_var with a :full_name, :color, and :position (but you can call your variables almost anything you want):
53
+
54
+ my_data = SimpleTimeSeries.new(:time_vars => {'dows' => dows,
55
+ 'dates' => dates,
56
+ 'full_dates' => full_dates},
57
+ :data_vars => {'pizzas' => pizzas,
58
+ 'miles' => miles,
59
+ 'tasks_done' => tasks_done},
60
+ :attribs => {'pizzas' => {:full_name => 'Pizzas Eaten', :color => 'red', :position => 2},
61
+ 'miles' => {:full_name => 'Miles Run', :color => 'green', :position => 3},
62
+ 'tasks_done' => {:full_name => 'Tasks Completed', :color => 'yellow', :position => 1}
63
+ } )
64
+
65
+ After doing so, you can then grab these values:
66
+
67
+ my_data.full_name('pizzas') # returns 'Pizzas Eaten'
68
+ my_data.full_name('miles') # returns 'Miles Run'
69
+ my_data.color('miles') # returns 'green'
70
+ my_data.color('tasks_done') # returns 'yellow'
71
+ my_data.position('pizzas') # returns 2
72
+ my_data.position('miles') # returns 3
73
+
74
+ You can easily access the value of any data variable for any value of one of your time variables via xxx_on methods created for each of your data_vars (here called 'pizzas_on,' 'miles_on' and 'tasks_done_on'):
53
75
 
54
76
  puts "Pizzas eaten on Tuesday: #{my_data.pizzas_on('Tuesday')}" # prints 1
55
77
  puts "Pizzas eaten on 2014-01-03: #{my_data.pizzas_on('2014-01-03')}" # prints 1
@@ -2,15 +2,24 @@ class SimpleTimeSeries
2
2
 
3
3
  DEBUG = false
4
4
 
5
- attr_accessor :time_vars, :data_vars
5
+ attr_accessor :time_vars, :data_vars, :attribs
6
6
 
7
7
  def initialize(opts)
8
8
  @time_vars = opts[:time_vars]
9
9
  @data_vars = opts[:data_vars]
10
+ @attribs = opts[:attribs]
10
11
  define_data_methods_and_set_values
11
12
  define_time_methods_and_set_values
12
13
  end
13
14
 
15
+ def method_missing(meth, *args, &block)
16
+ begin
17
+ attribs[args[0]][meth]
18
+ rescue
19
+ super
20
+ end
21
+ end
22
+
14
23
  def find(what, date, end_date=nil, opts={})
15
24
  puts "Calling send(#{what}_on, #{date}, #{end_date}, #{opts})" if DEBUG
16
25
  send((what + '_on').to_sym, date, end_date, opts)
@@ -1,3 +1,3 @@
1
1
  class SimpleTimeSeries
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -14,7 +14,20 @@ describe SimpleTimeSeries do
14
14
  'tasks_done' => @tasks_done, 'empty' => []},
15
15
  :time_vars =>
16
16
  {'dows' => @dows, 'dates' => @dates,
17
- 'full_dates' => @full_dates})
17
+ 'full_dates' => @full_dates},
18
+ :attribs => {'pizzas' => {:full_name => 'Pizzas Eaten', :color => 'red', :position => 2},
19
+ 'miles' => {:full_name => 'Miles Run', :color => 'green', :position => 3},
20
+ 'tasks_done' => {:full_name => 'Tasks Completed', :color => 'yellow', :position => 1}
21
+ } )
22
+ end
23
+
24
+ it "finds values in :attribs" do
25
+ @my_data.full_name('pizzas').should == 'Pizzas Eaten'
26
+ @my_data.full_name('miles').should == 'Miles Run'
27
+ @my_data.color('miles').should == 'green'
28
+ @my_data.color('tasks_done').should == 'yellow'
29
+ @my_data.position('pizzas').should == 2
30
+ @my_data.position('miles').should == 3
18
31
  end
19
32
 
20
33
  it "is creatable" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_time_series
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Lavin