Module: Dill::WidgetParts::Struct::ClassMethods

Defined in:
lib/dill/widgets/parts/struct.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, selector, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dill/widgets/parts/struct.rb', line 9

def attribute(name, selector, &block)
  child = widget(name, selector, &block)

  class_eval <<-WIDGET
    def #{name}
      widget(:#{name}).value
    end
  WIDGET

  child
end

#boolean(name, selector, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dill/widgets/parts/struct.rb', line 21

def boolean(name, selector, &block)
  child = widget(name, selector, &block)

  class_eval <<-WIDGET
    def #{name}?
      widget(:#{name}).value
    end
  WIDGET

  child.class_eval <<-VALUE
    def value
      Dill::Conversions::Boolean(text)
    end
  VALUE

  child
end

#date(name, selector, &block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dill/widgets/parts/struct.rb', line 39

def date(name, selector, &block)
  child = attribute(name, selector, &block)

  child.class_eval <<-VALUE
    def value
      Date.parse(text)
    end
  VALUE

  child
end

#float(name, selector, &block) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dill/widgets/parts/struct.rb', line 51

def float(name, selector, &block)
  child = attribute(name, selector, &block)

  child.class_eval <<-VALUE
    def value
      Float(text)
    end
  VALUE

  child
end

#integer(name, selector, &block) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/dill/widgets/parts/struct.rb', line 63

def integer(name, selector, &block)
  child = attribute(name, selector, &block)

  child.class_eval <<-VALUE
    def value
      Integer(text)
    end
  VALUE

  child
end

#list(name, selector, options = {}, &block) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/dill/widgets/parts/struct.rb', line 75

def list(name, selector, options = {}, &block)
  child = widget(name, selector, Dill::List) do
    item options[:item_selector], options[:item_class] || ListItem
  end

  class_eval <<-WIDGET
    def #{name}
      widget(:#{name}).value
    end
  WIDGET

  child.class_eval(&block) if block_given?

  child
end

#string(name, *args, &block) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/dill/widgets/parts/struct.rb', line 91

def string(name, *args, &block)
  child = attribute(name, *args, &block)

  child.class_eval <<-VALUE
    def value
      text
    end
  VALUE

  child
end

#time(name, *args, &block) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/dill/widgets/parts/struct.rb', line 103

def time(name, *args, &block)
  child = attribute(name, *args, &block)

  child.class_eval <<-VALUE
    def value
      Time.parse(text)
    end
  VALUE

  child
end