Module: Josean::Objects

Defined in:
lib/josean/objects.rb

Class Method Summary collapse

Class Method Details

.button(name, url, style) ⇒ Object

Creates a button item for the section name Name of the label action action name that will be triggered style Hash containing the style



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/josean/objects.rb', line 58

def self.button name, url, style
  if valid_name(name) and valid_url(url) and valid_style(style)
    {
      type: 'label',
      text: name,
      style: style,
      href: {
        url: url
      }
    }
  else
    nil
  end
end

.image(url, style) ⇒ Object

Creates an image item for the section url Url to which it points style Hash containing the style



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/josean/objects.rb', line 76

def self.image url, style
  if valid_url(url) and valid_style(style)
    {
      type: "image",
      url: url,
      style: style
    }
  else
    nil
  end
end

.label(name, style) ⇒ Object

Creates a label item for the section name Name of the label style Hash containing the style



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/josean/objects.rb', line 25

def self.label name, style
  if valid_name(name) and valid_style(style)
    {
      type: 'label',
      text: name,
      style: style,
    }
  else
    nil
  end
end

.map(coordinates, width, height, pins, style) ⇒ Object

Creates a map item for the section style Hash containing the style



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/josean/objects.rb', line 121

def self.map coordinates, width, height, pins, style
  if valid_coordinates(coordinates) and valid_radio(width) and valid_radio(height) and valid_pins(pins) and valid_style(style)

    output = {
      type: "map",
      region: {
        coord: coordinates.join(','),
        width: width.to_s,
        height: height.to_s
      },
      style: style
    }
    if pins.any?
      output[:pins] = pins.map do |p|
        pin p[:title], p[:description], p[:coord], p[:style]
      end
    end
    output
  else
    nil
  end
end

.pin(name, description, coordinates, style) ⇒ Object

Creates a pin item for a map for the section style Hash containing the style



146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/josean/objects.rb', line 146

def self.pin name, description, coordinates, style
  if valid_name(name) and valid_name(description) and valid_coordinates(coordinates) and valid_style(style)
    {
      title: name,
      description: description,
      coord: coordinates.join(','),
      style: style
    }
  else
    nil
  end
end

.slider(name, value, action, style) ⇒ Object

Creates an image item for the section url Url to which it points style Hash containing the style



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/josean/objects.rb', line 91

def self.slider name, value, action, style
  if valid_name(name) and valid_value_slider(value) and valid_action(action) and valid_style(style)
    {
      type: "slider",
      name: name,
      value: value.to_s,
      action: {
        "trigger": action
      }
    }
  else
    nil
  end
end

.space(style) ⇒ Object

Creates a space item for the section style Hash containing the style



108
109
110
111
112
113
114
115
116
117
# File 'lib/josean/objects.rb', line 108

def self.space style
  if valid_style(style)
    {
      type: "space",
      style: style 
    }
  else
    nil
  end
end

.switch(name, value, action, style) ⇒ Object

Creates a switch



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/josean/objects.rb', line 5

def self.switch name, value, action, style
  if valid_name(name) and valid_value_switch(value) and valid_action(action) and valid_style(style)
    {
      type: 'switch',
      name: name,
      value: value,
      action: {
        trigger: action,
        options: {
          item: "Name of the switch #{name}"
        }
      }
    }
  else
    nil
  end
end

.textfield(name, style) ⇒ Object

Creates a textfield item for the section name Name of the label style Hash containing the style



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/josean/objects.rb', line 40

def self.textfield name, style
  if valid_name(name) and valid_style(style)
    {
      type: 'textfield',
      name: name,
      keyboard: 'email',
      placeholder: "Enter #{name.downcase}",
      style: style 
    }
  else
    nil
  end
end