Class: HtmlMeta::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/html_meta/data.rb

Instance Method Summary collapse

Constructor Details

#initializeData

Returns a new instance of Data.



5
6
7
# File 'lib/html_meta/data.rb', line 5

def initialize
	@data = {}
end

Instance Method Details

#data(scope = :default) ⇒ Object



13
14
15
# File 'lib/html_meta/data.rb', line 13

def data(scope = :default)
	@data[scope] ||= {}
end

#get(scope, key = nil) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/html_meta/data.rb', line 17

def get(scope, key = nil)
	if key.nil?
data(scope)
			else
		data(scope).fetch(key) { nil } 
	end
end

#meta(key, value = nil, options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/html_meta/data.rb', line 36

def meta(key, value = nil, options = {})
			if value.nil?
		return get(:default, key)
	else
		if key == :title && 
			unless options.key?(:separator)
		options[:separator] = HtmlMeta.configuration.title_separator 
	end
end
		set(:default, key, value, options)	  			
	end
end

#open_graph(key, value = nil, options = {}) ⇒ Object Also known as: og



49
50
51
52
53
54
55
56
# File 'lib/html_meta/data.rb', line 49

def open_graph(key, value = nil, options = {})
	if value.nil?
		return get(:og, key)
	else
		#we are setting a value
		set(:og, key, value, options)	  			
	end
end

#resetObject



9
10
11
# File 'lib/html_meta/data.rb', line 9

def reset
	@data = {}
end

#set(scope, key, value = nil, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/html_meta/data.rb', line 25

def set(scope, key, value = nil, options = {})
			separator = options.fetch(:separator, ' ')
			value = Array(value)
			if options.fetch(:prepend, false)
value << data(scope).fetch(key, '')
			elsif options.fetch(:append, false)
value.insert(0, data(scope).fetch(key, ''))
			end
			data(scope)[key] = value.compact.join(separator)
end