9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/raudi/avr/pin_states.rb', line 9
def self.included(klass)
klass.class_eval do
attr_accessor :states, :state, :state_params
Info.pin_states.each do |pin_state|
define_method :get_state do |pin_state|
states.detect { |state| state =~ Regexp.new("\\A(#{pin_state})(_\d+)?") }
end
define_method :get_state! do |pin_state|
valid_state = get_state(pin_state)
raise "#{to_s} can be #{pin_state}" unless valid_state
valid_state
end
define_method "#{pin_state}!" do |*args|
self.state = get_state!(pin_state)
self.state_params = args.first
end
define_method "#{pin_state}?" do |*args|
self.state == get_state(pin_state)
end
define_method "can_be_#{pin_state}?" do |*args|
return unless full_state = get_state(pin_state)
if(number = args.first)
return unless full_state[number.to_s]
end
true
end
end
end
end
|