Class: Templatr::Tag

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/templatr/tag.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#valueObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/templatr/tag.rb', line 32

def value
  if !@value.nil?
    @value
  elsif custom_tag? || string?
    string_value
  elsif text?
    text_value
  elsif select_one?
    field_value.to_s
  elsif select_multiple?
    field_values.collect(&:to_s)
  elsif boolean?
    boolean_value
  elsif float?
    float_value
  elsif integer?
    integer_value
  elsif integer_with_uncertainty?
    _value = integer_value.to_s
    _value << " ± #{integer_value_uncertainty}" if integer_value_uncertainty
    _value
  else
    raise "Unknown Field Type: #{field.field_type.inspect}"
  end
end

Class Method Details

.templatable_classObject



20
21
22
# File 'app/models/templatr/tag.rb', line 20

def self.templatable_class
  self.to_s[/[A-Z][a-z]+/].constantize
end

Instance Method Details

#custom_tag?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/templatr/tag.rb', line 24

def custom_tag?
  !field
end

#field_group_idObject



62
63
64
# File 'app/models/templatr/tag.rb', line 62

def field_group_id
  field.field_group_id if field
end

#field_value=(value) ⇒ Object

Allow field value to be set by passing a string



67
68
69
# File 'app/models/templatr/tag.rb', line 67

def field_value=(value)
  super find_or_create_field_value(value)
end

#field_values=(value) ⇒ Object

Allow field value to be set by passing a string



72
73
74
# File 'app/models/templatr/tag.rb', line 72

def field_values=(value)
  super Array.wrap(value).collect {|value| find_or_create_field_value(value) }
end

#nameObject



28
29
30
# File 'app/models/templatr/tag.rb', line 28

def name
  custom_tag? ? self['name'] : field.name
end

#to_sObject



58
59
60
# File 'app/models/templatr/tag.rb', line 58

def to_s
  value.is_a?(Array) ? value.join(', ') : value
end