Class: Adrift::Pattern
- Inherits:
-
Object
- Object
- Adrift::Pattern
- Defined in:
- lib/adrift/pattern.rb
Overview
Provides a way for Attachment to generally define its paths and urls, allowing to specialize them for every individual instance.
In order to do this, a Pattern is build from a String comprised of Tags (or more precisely, their labels) and when is asked to be specialized for a given Attachment and style, it replaces these Tags with they specialized values for that Attachment and that style.
Defined Under Namespace
Modules: Tags
Instance Attribute Summary collapse
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Class Method Summary collapse
-
.tags ⇒ Object
Tags every instance of Pattern will be able to recognize (and specialize).
Instance Method Summary collapse
-
#initialize(string) ⇒ Pattern
constructor
Creates a new Pattern from a
string
comprised of one o more tag’s labels. -
#specialize(options = {}) ⇒ Object
Returns #string with the known Tags replaced with their specific values the given
options
.
Constructor Details
#initialize(string) ⇒ Pattern
Creates a new Pattern from a string
comprised of one o more tag’s labels.
194 195 196 |
# File 'lib/adrift/pattern.rb', line 194 def initialize(string) @string = string.dup end |
Instance Attribute Details
#string ⇒ Object (readonly)
Returns the value of attribute string.
190 191 192 |
# File 'lib/adrift/pattern.rb', line 190 def string @string end |
Class Method Details
.tags ⇒ Object
Tags every instance of Pattern will be able to recognize (and specialize).
186 187 188 |
# File 'lib/adrift/pattern.rb', line 186 def self. @tags ||= [] end |
Instance Method Details
#specialize(options = {}) ⇒ Object
Returns #string with the known Tags replaced with their specific values the given options
. While options
is just a Hash, it’s expected to include the Attachment this Pattern belongs to (:attachment
key), and the selected style (:style
key).
202 203 204 205 206 |
# File 'lib/adrift/pattern.rb', line 202 def specialize(={}) .inject(string) do |result, tag| result.gsub(tag.label) { tag.specialize() } end end |