Class: ActiveSensor::Parameter

Inherits:
Controller show all
Defined in:
lib/active_sensor/parameter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Controller

has_parameter, inherited, parameters, parameters=, #retrieve

Constructor Details

#initialize(name, options = {}) ⇒ Parameter

Returns a new instance of Parameter.


5
6
7
8
9
10
# File 'lib/active_sensor/parameter.rb', line 5

def initialize(name, options = {})
  @name = name
  @default = options[:default]
  @required = !options[:required].is_a?(FalseClass)
  @type = options[:type] || :text
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default


3
4
5
# File 'lib/active_sensor/parameter.rb', line 3

def default
  @default
end

#nameObject (readonly)

Returns the value of attribute name


3
4
5
# File 'lib/active_sensor/parameter.rb', line 3

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type


3
4
5
# File 'lib/active_sensor/parameter.rb', line 3

def type
  @type
end

Instance Method Details

#human_nameObject


16
17
18
# File 'lib/active_sensor/parameter.rb', line 16

def human_name
  @name.to_s.humanize
end

#normalize!(value) ⇒ Object

Check and normalize value


21
22
23
24
25
26
27
28
# File 'lib/active_sensor/parameter.rb', line 21

def normalize!(value)
  if value.blank?
    return default if default
    raise MissingParameter, "Parameter #{@name} cannot be blank" if required?
    return nil
  end
  value
end

#required?Boolean

Returns:

  • (Boolean)

12
13
14
# File 'lib/active_sensor/parameter.rb', line 12

def required?
  @required
end