Class: LiquidComponent::Variable

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid-component/variable.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(variable_name, variable_metadata) ⇒ Variable

Returns a new instance of Variable.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/liquid-component/variable.rb', line 13

def initialize(variable_name, )
  self.required = true

  self.name = if variable_name.end_with? "?"
    self.required = false
    variable_name.sub(/\?$/, "").to_sym
  else
    variable_name.to_sym
  end

  if .is_a?(Array)
    self.type = [0].to_sym
    self.description = [1]
  else
    self.type = .to_sym
  end
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/liquid-component/variable.rb', line 3

def description
  @description
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/liquid-component/variable.rb', line 3

def name
  @name
end

#requiredObject

Returns the value of attribute required.



3
4
5
# File 'lib/liquid-component/variable.rb', line 3

def required
  @required
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/liquid-component/variable.rb', line 3

def type
  @type
end

Class Method Details

.parse(variables) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/liquid-component/variable.rb', line 5

def self.parse(variables)
  return [] if variables.nil?

  variables.map do |variable_name, |
    new(variable_name, )
  end
end

Instance Method Details

#to_hObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/liquid-component/variable.rb', line 31

def to_h
  h = {
    name: name,
    type: type,
    required: required
  }
  h[:description] = description if description

  h
end