Class: OpenStruct

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/seo.rb

Instance Method Summary collapse

Instance Method Details

#new_ostruct_member(name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sinatra/seo.rb', line 6

def new_ostruct_member(name)
  name = name.to_sym
  
  @table[name] = case name
    when :title then @table[name][0, 60]
    when :description then @table[name][0, 160]
    when :keywords then @table[name].split(" ")[0, 15].join(" ")
    else @table[name]
  end
  
  unless self.respond_to?(name)
    class << self; self; end.class_eval do
      define_method(name) {@table[name].is_a?(Hash) ? OpenStruct.new(@table[name]) : @table[name]}
    end
  end
end