Class: Glib::Json::NewDynamicText::TextSpec

Inherits:
Struct
  • Object
show all
Defined in:
app/controllers/concerns/glib/json/new_dynamic_text.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argsObject

Returns the value of attribute args

Returns:

  • (Object)

    the current value of args



107
108
109
# File 'app/controllers/concerns/glib/json/new_dynamic_text.rb', line 107

def args
  @args
end

#propObject

Returns the value of attribute prop

Returns:

  • (Object)

    the current value of prop



107
108
109
# File 'app/controllers/concerns/glib/json/new_dynamic_text.rb', line 107

def prop
  @prop
end

#viewObject

Returns the value of attribute view

Returns:

  • (Object)

    the current value of view



107
108
109
# File 'app/controllers/concerns/glib/json/new_dynamic_text.rb', line 107

def view
  @view
end

Instance Method Details

#substitute_image_with(images) ⇒ Object



112
113
114
115
116
117
118
119
120
# File 'app/controllers/concerns/glib/json/new_dynamic_text.rb', line 112

def substitute_image_with(images)
  view[prop] = view[prop].gsub(/\{\{image(\d)\}\}/) {
    if image = images[$1.to_i - 1]
      ApplicationController.helpers.glib_dynamic_image_url(image.blob.key)
    else
      "{{image#{$1}}}"
    end
  }
end

#substitute_with(text) ⇒ Object



108
109
110
# File 'app/controllers/concerns/glib/json/new_dynamic_text.rb', line 108

def substitute_with(text)
  view[prop] = text.gsub(/\{\{(\w+)\}\}/) { args.fetch($1, "{{#{$1}}}") }
end