Class: CultomePlayer::Objects::Parameter

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/cultome_player/objects/parameter.rb

Instance Method Summary collapse

Methods included from Utils

#arrange_in_columns, #display, #display_over, #ensure_db_schema, #is_true_value?, #recreate_db_schema, #swallow_stdout, #to_display_list, #with_connection

Constructor Details

#initialize(data) ⇒ Parameter

Initialize a parameter with the data provided.

Parameters:

  • data (Hash)

    Contains the keys :criteria, :value, :type



9
10
11
# File 'lib/cultome_player/objects/parameter.rb', line 9

def initialize(data)
  @data = data
end

Instance Method Details

#criteriaObject

Get the criteria asocciated with the parameter, if any.



14
15
16
17
# File 'lib/cultome_player/objects/parameter.rb', line 14

def criteria
  return nil if @data[:criteria].nil?
  @data[:criteria].to_sym
end

#raw_valueString

Return the value as the user input typed (no conversions).

Returns:

  • (String)

    The values of the parameter as the user typed.



32
33
34
# File 'lib/cultome_player/objects/parameter.rb', line 32

def raw_value
  @data[:value]
end

#to_sObject



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cultome_player/objects/parameter.rb', line 43

def to_s
  return case @data[:type]
    when :literal then @data[:value]
    when :criteria then "#{@data[:criteria]}:#{@data[:value]}"
    when :number then @data[:value]
    when :object then "@#{@data[:value]}"
    when :boolean then @data[:value]
    when :path then @data[:value]
    when :bubble then @data[:value]
    else value
  end
end

#typeSymbol

Returns the type associated with the parameter.

Returns:

  • (Symbol)

    The type of the parameter.



39
40
41
# File 'lib/cultome_player/objects/parameter.rb', line 39

def type
  @data[:type]
end

#valueObject

Returns the value associated with the parameter in its appropiated type.

Returns:

  • (Object)

    The value of the parameter.



22
23
24
25
26
27
# File 'lib/cultome_player/objects/parameter.rb', line 22

def value
  return is_true_value?(@data[:value]) if @data[:type] == :boolean
  return @data[:value].to_i if @data[:type] == :number
  return @data[:value].to_sym if @data[:type] == :object
  return raw_value
end