hue-lib 0.6.0 → 0.7.0

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.
@@ -0,0 +1,91 @@
1
+ # Encoding: UTF-8
2
+ require 'spec_helper.rb'
3
+
4
+ describe Hue::Colors::HueSaturation do
5
+
6
+ context 'when initialized with valid values' do
7
+ color = described_class.new(2e4, 122)
8
+
9
+ it 'should report those values' do
10
+ color.hue.should == 20_000
11
+ color.saturation.should == 122
12
+ end
13
+
14
+ it 'should report hue in degrees and a closed unit interval' do
15
+ color.hue_in_degrees.should == 109.86328125
16
+ color.hue_in_unit_interval.should == 0.30517578125
17
+ end
18
+
19
+ it 'should report saturation in a closed unit interval' do
20
+ color.saturation_in_unit_interval.should == 0.47843137254901963
21
+ end
22
+
23
+ it 'should have a string representation' do
24
+ color.to_s.should == "Hue=20000, Saturation=122"
25
+ end
26
+
27
+ it 'should have a hash representation' do
28
+ color.to_hash.should == {hue: 20_000, sat: 122}
29
+ end
30
+
31
+ it 'should have an RGB representation' do
32
+ color.to_rgb.should == Hue::Colors::RGB.new(153,255,132)
33
+ end
34
+
35
+ context 'when allowing change to the color values' do
36
+ it 'should allow setting the maximum hue' do
37
+ color.hue = 70_000
38
+ color.hue.should == described_class::HUE_MAX
39
+ color.hue_in_degrees.should == 360
40
+ color.hue_in_unit_interval.should == 1.0
41
+ end
42
+
43
+ it 'should allow setting the minimum hue' do
44
+ color.hue = -1000
45
+ color.hue.should == described_class::HUE_MIN
46
+ color.hue_in_degrees.should == 0
47
+ color.hue_in_unit_interval.should == 0.0
48
+ end
49
+
50
+ it 'should allow setting the maximum saturation' do
51
+ color.saturation = 300
52
+ color.sat.should == described_class::SATURATION_MAX
53
+ color.sat_in_unit_interval.should == 1.0
54
+ end
55
+
56
+ it 'should allow setting the minimum saturation' do
57
+ color.saturation = -1
58
+ color.sat.should == described_class::SATURATION_MIN
59
+ color.sat_in_unit_interval.should == 0.0
60
+ end
61
+ end
62
+
63
+ context 'when initialized with other values' do
64
+ it 'should accept hue and saturation values' do
65
+ color = described_class.new(3e4, 200)
66
+ color.hue.should == 3e4
67
+ color.sat.should == 200
68
+ end
69
+
70
+ it 'should accept a percentage of the hue scale with saturation value' do
71
+ color = described_class.new('20%', 150)
72
+ color.hue.should == 13107
73
+ color.sat.should == 150
74
+ end
75
+
76
+ it 'should accept a hue value with a percentage of the saturation scale' do
77
+ color = described_class.new(7e4, '100%')
78
+ color.hue.should == Hue::Colors::HueSaturation::HUE_MAX
79
+ color.sat.should == Hue::Colors::HueSaturation::SATURATION_MAX
80
+ end
81
+
82
+ it 'should accept hue and saturation strings' do
83
+ color = described_class.new("30_000", "1333")
84
+ color.hue.should == 3e4
85
+ color.sat.should == Hue::Colors::HueSaturation::SATURATION_MAX
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ end
@@ -0,0 +1,64 @@
1
+ # Encoding: UTF-8
2
+ require 'spec_helper.rb'
3
+
4
+ describe Hue::Colors::RGB do
5
+
6
+ context 'when initialized with a valid values' do
7
+ color = described_class.new(64, 128, 248)
8
+
9
+ it 'should report those values' do
10
+ color.red.should == 64
11
+ color.green.should == 128
12
+ color.blue.should == 248
13
+ end
14
+
15
+ it 'should have a string representation' do
16
+ color.to_s.should == "RGB≈[64, 128, 248]"
17
+ end
18
+
19
+ it 'should have a hash representation' do
20
+ color.to_hash.should == {hue: 21845, sat: 127, bri: 255 }
21
+ end
22
+
23
+ it 'should have an RGB representation' do
24
+ color.to_rgb.should == color
25
+ end
26
+
27
+ context 'when allowing change to the color values' do
28
+ it 'should allow setting the maximum' do
29
+ color.red = 300
30
+ color.red.should == described_class::MAX
31
+ color.green = 255
32
+ color.green.should == described_class::MAX
33
+ color.red = 256
34
+ color.red.should == described_class::MAX
35
+ end
36
+
37
+ it 'should allow setting the minimum' do
38
+ color.red = 0
39
+ color.red.should == described_class::MIN
40
+ color.green = -1
41
+ color.green.should == described_class::MIN
42
+ color.red = -256
43
+ color.red.should == described_class::MIN
44
+ end
45
+ end
46
+
47
+ context 'when initializing' do
48
+ it 'should allow strings' do
49
+ color = described_class.new('200', '100', '50')
50
+ color.red.should == 200
51
+ color.green.should == 100
52
+ color.blue.should == 50
53
+ end
54
+
55
+ it 'should allow percentages' do
56
+ color = described_class.new('10%', '100%', '50%')
57
+ color.red.should == 26
58
+ color.green.should == 255
59
+ color.blue.should == 128
60
+ end
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,51 @@
1
+ # Encoding: UTF-8
2
+ require 'spec_helper.rb'
3
+
4
+ describe Hue::Colors::XY do
5
+
6
+ context 'when initialized with a valid values' do
7
+ color = described_class.new(0.5, 0.5)
8
+
9
+ it 'should report those values' do
10
+ color.x.should == 0.5
11
+ color.y.should == 0.5
12
+ end
13
+
14
+ it 'should have a string representation' do
15
+ color.to_s.should == "XY=[0.5, 0.5]"
16
+ end
17
+
18
+ it 'should have a hash representation' do
19
+ color.to_hash.should == {xy: [0.5, 0.5]}
20
+ end
21
+
22
+ it 'should have an RGB representation' do
23
+ color.to_rgb.should == Hue::Colors::RGB.new(217,209,41)
24
+ end
25
+
26
+ context 'when allowing change to the color values' do
27
+ it 'should allow setting the maximum' do
28
+ color.x = 1.1
29
+ color.x.should == described_class::MAX
30
+ color.y = 2
31
+ color.y.should == described_class::MAX
32
+ end
33
+
34
+ it 'should allow setting the minimum' do
35
+ color.x = -1
36
+ color.x.should == described_class::MIN
37
+ color.y = 0
38
+ color.y.should == described_class::MIN
39
+ end
40
+ end
41
+
42
+ context 'when initializing' do
43
+ it 'should allow strings' do
44
+ color = described_class.new('0.22', '10.00')
45
+ color.x.should == 0.22
46
+ color.y.should == 1.00
47
+ end
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,92 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Hue::Colors do
4
+
5
+ context 'when #parse_state is used' do
6
+ it 'can return a ColorTemperature' do
7
+ color = described_class.parse_state({'colormode' => 'ct', 'ct' => 500})
8
+ color.should be_a(Hue::Colors::ColorTemperature)
9
+ color.mired.should == 500
10
+ end
11
+
12
+ it 'can return HueSaturation' do
13
+ color = described_class.parse_state({'colormode' => 'hs', 'hue' => 30_000, 'sat' => 150})
14
+ color.should be_a(Hue::Colors::HueSaturation)
15
+ color.hue.should == 30_000
16
+ color.sat.should == 150
17
+ end
18
+
19
+ it 'can return XY' do
20
+ color = described_class.parse_state({'colormode' => 'xy', 'xy' => [0.8, 0.2]})
21
+ color.should be_a(Hue::Colors::XY)
22
+ color.x.should == 0.8
23
+ color.y.should == 0.2
24
+ end
25
+
26
+ it 'throws error if no mode is passed' do
27
+ lambda do
28
+ described_class.parse_state({})
29
+ end.should raise_error(Hue::Error, /Unknown or missing state/)
30
+ end
31
+ end
32
+
33
+ context 'when #parse is used' do
34
+ it 'can return a ColorTemperature with single value' do
35
+ color = described_class.parse("5000")
36
+ color.should be_a(Hue::Colors::ColorTemperature)
37
+ color.kelvin.should == 5000
38
+
39
+ color = described_class.parse(130)
40
+ color.should be_a(Hue::Colors::ColorTemperature)
41
+ color.mired.should == Hue::Colors::ColorTemperature::MIRED_MIN
42
+
43
+ color = described_class.parse("100%")
44
+ color.should be_a(Hue::Colors::ColorTemperature)
45
+ color.mired.should == Hue::Colors::ColorTemperature::MIRED_MAX
46
+ end
47
+
48
+ it 'can return HueSaturation' do
49
+ color = described_class.parse(*[3e4, 200])
50
+ color.should be_a(Hue::Colors::HueSaturation)
51
+ color.hue.should == 3e4
52
+ color.sat.should == 200
53
+
54
+ color = described_class.parse(*['20%', 150])
55
+ color.should be_a(Hue::Colors::HueSaturation)
56
+ color.hue.should == 13107
57
+ color.sat.should == 150
58
+
59
+ color = described_class.parse(*[7e4, '100%'])
60
+ color.should be_a(Hue::Colors::HueSaturation)
61
+ color.hue.should == Hue::Colors::HueSaturation::HUE_MAX
62
+ color.sat.should == Hue::Colors::HueSaturation::SATURATION_MAX
63
+ end
64
+
65
+ it 'can return XY' do
66
+ color = described_class.parse(*[0.2, 0.5])
67
+ color.should be_a(Hue::Colors::XY)
68
+ color.x.should == 0.2
69
+ color.y.should == 0.5
70
+ end
71
+
72
+ it 'can return RGB' do
73
+ color = described_class.parse(*[0.0, 300, 155])
74
+ color.should be_a(Hue::Colors::RGB)
75
+ color.red.should == 0
76
+ color.green.should == 255
77
+ color.blue.should == 155
78
+
79
+ color = described_class.parse(*['10%', '100%', '50%'])
80
+ color.should be_a(Hue::Colors::RGB)
81
+ color.red.should == 26
82
+ color.green.should == 255
83
+ color.blue.should == 128
84
+ end
85
+
86
+ it 'throws error if no mode is passed' do
87
+ lambda do
88
+ described_class.parse
89
+ end.should raise_error(Hue::Error, /Unable to parse to color:/)
90
+ end
91
+ end
92
+ end
data/spec/hue_spec.rb CHANGED
@@ -77,4 +77,12 @@ describe Hue do
77
77
  end
78
78
  end
79
79
 
80
+ context 'contains some utility methods' do
81
+ it '#percent_to_unit_interval should convert a string with percent to a unit interval' do
82
+ described_class.percent_to_unit_interval('1%').should == 0.01
83
+ described_class.percent_to_unit_interval('10%').should == 0.1
84
+ described_class.percent_to_unit_interval('100%').should == 1.00
85
+ end
86
+ end
87
+
80
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hue-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-30 00:00:00.000000000 Z
13
+ date: 2013-02-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -76,7 +76,9 @@ dependencies:
76
76
  - - ! '>='
77
77
  - !ruby/object:Gem::Version
78
78
  version: 1.8.0
79
- description: Ruby library for controlling Phillips Hue light bridge.
79
+ description: ! "Library allowing registration and invocation of a registered Philips
80
+ Hue app.\n Convinient objects allow executing commands on the bridge or individual
81
+ bulbs."
80
82
  email:
81
83
  - birkirb@stoicviking.net
82
84
  executables: []
@@ -89,8 +91,16 @@ files:
89
91
  - Rakefile
90
92
  - hue-lib.gemspec
91
93
  - lib/hue.rb
94
+ - lib/hue/animations/candle.rb
95
+ - lib/hue/animations/sunrise.rb
92
96
  - lib/hue/bridge.rb
93
97
  - lib/hue/bulb.rb
98
+ - lib/hue/colors.rb
99
+ - lib/hue/colors/color.rb
100
+ - lib/hue/colors/color_temperature.rb
101
+ - lib/hue/colors/hue_saturation.rb
102
+ - lib/hue/colors/rgb.rb
103
+ - lib/hue/colors/xy.rb
94
104
  - lib/hue/config/abstract.rb
95
105
  - lib/hue/config/application.rb
96
106
  - lib/hue/config/bridge.rb
@@ -98,6 +108,12 @@ files:
98
108
  - spec/config/bridges.yml
99
109
  - spec/hue/bridge_spec.rb
100
110
  - spec/hue/bulb_spec.rb
111
+ - spec/hue/colors/color_spec.rb
112
+ - spec/hue/colors/color_temperature_spec.rb
113
+ - spec/hue/colors/hue_saturation_spec.rb
114
+ - spec/hue/colors/rgb_spec.rb
115
+ - spec/hue/colors/xy_spec.rb
116
+ - spec/hue/colors_spec.rb
101
117
  - spec/hue/config/abstract_spec.rb
102
118
  - spec/hue/config/application_spec.rb
103
119
  - spec/hue/config/bridge_spec.rb
@@ -136,6 +152,6 @@ rubyforge_project: hue-lib
136
152
  rubygems_version: 1.8.23
137
153
  signing_key:
138
154
  specification_version: 3
139
- summary: Ruby library for controlling Phillips Hue light bridge.
155
+ summary: Ruby library for controlling the Philips Hue system's lights and bridge.
140
156
  test_files: []
141
157
  has_rdoc: