Class: Knipper::Pattern::PatternLine

Inherits:
Object
  • Object
show all
Defined in:
lib/knipper/pattern/pattern_line.rb

Constant Summary collapse

PATTERN =
/\A(\d+),(\d+),(\d+),(\d+)\z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ PatternLine

Returns a new instance of PatternLine.



21
22
23
24
25
# File 'lib/knipper/pattern/pattern_line.rb', line 21

def initialize(attributes = {})
  attributes.each do |name, value|
    send("#{name}=", value)
  end
end

Instance Attribute Details

#blueObject

Returns the value of attribute blue.



4
5
6
# File 'lib/knipper/pattern/pattern_line.rb', line 4

def blue
  @blue
end

#greenObject

Returns the value of attribute green.



4
5
6
# File 'lib/knipper/pattern/pattern_line.rb', line 4

def green
  @green
end

#millisObject

Returns the value of attribute millis.



4
5
6
# File 'lib/knipper/pattern/pattern_line.rb', line 4

def millis
  @millis
end

#redObject

Returns the value of attribute red.



4
5
6
# File 'lib/knipper/pattern/pattern_line.rb', line 4

def red
  @red
end

Class Method Details

.parse(s) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/knipper/pattern/pattern_line.rb', line 8

def self.parse(s)
  parts = PATTERN.match(s)
  raise "Unrecognized pattern -- #{s}" unless parts

  pattern_line = PatternLine.new
  pattern_line.millis = parts[1].to_i
  pattern_line.red = parts[2].to_i
  pattern_line.green = parts[3].to_i
  pattern_line.blue = parts[4].to_i
  
  pattern_line
end