class LiquidComponent::Variable

Attributes

description[RW]
name[RW]
required[RW]
type[RW]

Public Class Methods

new(variable_name, variable_metadata) click to toggle source
# File lib/liquid-component/variable.rb, line 13
def initialize(variable_name, variable_metadata)
  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 variable_metadata.is_a?(Array)
    self.type = variable_metadata[0].to_sym
    self.description = variable_metadata[1]
  else
    self.type = variable_metadata.to_sym
  end
end
parse(variables) click to toggle source
# File lib/liquid-component/variable.rb, line 5
def self.parse(variables)
  return [] if variables.nil?

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

Public Instance Methods

to_h() click to toggle source
# 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