Class: Aggeratio::Parameter

Inherits:
Object
  • Object
show all
Defined in:
lib/aggeratio/parameter.rb

Constant Summary collapse

TYPES =
[:record_list, :record, :string, :decimal, :integer, :date, :datetime].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Parameter.

Raises:

  • (ArgumentError)

6
7
8
9
10
11
12
13
14
# File 'lib/aggeratio/parameter.rb', line 6

def initialize(name, type, options = {})
  @name = name.to_s
  @type = type
  @options = options
  raise ArgumentError, "Type is unknown: #{@type.inspect}" unless TYPES.include?(@type)
  @default = @options[:default]
  raise ArgumentError, "Default value must be given for #{@name}" unless @default
  @foreign_class = @options[:of].to_s.camelcase.constantize if @options[:of]
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default


4
5
6
# File 'lib/aggeratio/parameter.rb', line 4

def default
  @default
end

#foreign_classObject (readonly)

Returns the value of attribute foreign_class


4
5
6
# File 'lib/aggeratio/parameter.rb', line 4

def foreign_class
  @foreign_class
end

#nameObject (readonly)

Returns the value of attribute name


4
5
6
# File 'lib/aggeratio/parameter.rb', line 4

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options


4
5
6
# File 'lib/aggeratio/parameter.rb', line 4

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type


4
5
6
# File 'lib/aggeratio/parameter.rb', line 4

def type
  @type
end

Class Method Details

.import(element) ⇒ Object

Import parameter form an XML node


17
18
19
20
21
22
23
24
25
# File 'lib/aggeratio/parameter.rb', line 17

def self.import(element)
  options = element.attributes.inject({}) do |hash, pair|
    hash[pair[0].to_sym] = pair[1].to_s
    hash
  end
  name = options.delete(:name).to_s
  type = options.delete(:type).to_s.tr('-', '_').to_sym
  new(name, type, options)
end

Instance Method Details

#human_nameObject


27
28
29
# File 'lib/aggeratio/parameter.rb', line 27

def human_name
  ::I18n.t("aggregator_parameters.#{name}", default: [:"labels.#{name}", :"attributes.#{name}", name.to_s.humanize])
end