Class: Cmsimple::Region
- Inherits:
-
Object
- Object
- Cmsimple::Region
- Defined in:
- app/models/cmsimple/region.rb
Instance Attribute Summary collapse
-
#snippets ⇒ Object
readonly
Returns the value of attribute snippets.
Instance Method Summary collapse
- #as_json ⇒ Object
- #build_snippets ⇒ Object
-
#initialize(region_hash = nil) ⇒ Region
constructor
A new instance of Region.
- #render_snippets ⇒ Object
- #to_s ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(region_hash = nil) ⇒ Region
Returns a new instance of Region.
4 5 6 7 8 9 |
# File 'app/models/cmsimple/region.rb', line 4 def initialize(region_hash=nil) @region_hash = (region_hash.presence || {}).dup @snippets = [] @html = value build_snippets end |
Instance Attribute Details
#snippets ⇒ Object (readonly)
Returns the value of attribute snippets.
3 4 5 |
# File 'app/models/cmsimple/region.rb', line 3 def snippets @snippets end |
Instance Method Details
#as_json ⇒ Object
36 37 38 |
# File 'app/models/cmsimple/region.rb', line 36 def as_json @region_hash end |
#build_snippets ⇒ Object
11 12 13 14 |
# File 'app/models/cmsimple/region.rb', line 11 def build_snippets return unless @region_hash.key?(:snippets) && @region_hash[:snippets].is_a?(Hash) @snippets = @region_hash[:snippets].collect {|id, hash| Snippet.new(id, hash)} end |
#render_snippets ⇒ Object
16 17 18 19 20 21 22 |
# File 'app/models/cmsimple/region.rb', line 16 def render_snippets @html = value snippets.each do |snippet| snippet_view = yield snippet @html.gsub!(snippet.matcher, snippet_view) end end |
#to_s ⇒ Object
32 33 34 |
# File 'app/models/cmsimple/region.rb', line 32 def to_s @html.presence || "" end |
#value ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/models/cmsimple/region.rb', line 24 def value begin @region_hash[:value] rescue => ex raise RegionValueError, "Unable to access invalid region hash: #{@region_hash.inspect}" end end |