Class: Lolita::Configuration::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/lolita/configuration/column.rb

Constant Summary collapse

MAX_TEXT_SIZE =
20

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Column

Returns a new instance of Column.



8
9
10
11
12
13
# File 'lib/lolita/configuration/column.rb', line 8

def initialize(*args,&block)
  self.set_attributes(*args)
  self.instance_eval(&block) if block_given?
  validate
  set_default_values
end

Instance Method Details

#format_from_type(value) ⇒ Object

TODO test



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/lolita/configuration/column.rb', line 33

def format_from_type(value) #TODO test
  if value
    if value.is_a?(String)
      value
    elsif value.is_a?(Integer)
      value
    elsif value.is_a?(Date)
      if defined?(I18n)
        I18n.localize(value, :format => :long)
      else
        value.to_s
      end
    elsif value.is_a?(Time)
      if defined?(I18n)
        I18n.localize(value, :format => :long)
      else
        value.to_s
      end
    else
      value.to_s
    end
  else
    ""
  end
end

#set_attributes(*args) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/lolita/configuration/column.rb', line 59

def set_attributes(*args)
  if !args.empty?
    if args[0].is_a?(Hash)
      args[0].each{|m,value|
        self.send("#{m}=".to_sym,value)
      }
    elsif args[0].is_a?(Symbol) || args[0].is_a?(String)
      self.name=args[0].to_s
    else
      raise ArgumentError.new("Lolita::Configuration::Column arguments must be Hash or Symbol or String instead of #{args[0].class}")
    end
  end
end

#with_format(value) ⇒ Object

column do

  name "UID"
  format do(values)
    values.first+values.last
  end
end

<%= column.with_format()%>



23
24
25
26
27
28
29
30
31
# File 'lib/lolita/configuration/column.rb', line 23

def with_format(value) #TODO test
  if @format.respond_to?(:call)
    @format.call(value)
  elsif @format && (value.is_a?(Time) || value.is_a?(Date))
    format_for_datetime(value)
  else
    format_from_type(value)
  end
end