class MetaInspector::Parsers::MetaTagsParser
Public Instance Methods
Source
# File lib/meta_inspector/parsers/meta_tags.rb, line 29 def charset @charset ||= (charset_from_meta_charset || charset_from_meta_content_type) end
Returns the charset from the meta tags, searching in this order: <meta charset=‘utf-8’ /> <meta http-equiv=“Content-Type” content=“text/html; charset=windows-1252” />
Source
# File lib/meta_inspector/parsers/meta_tags.rb, line 19 def meta meta_tag['name'] .merge(meta_tag['http-equiv']) .merge(meta_tag['property']) .merge('charset' => meta_tag['charset']) end
Source
# File lib/meta_inspector/parsers/meta_tags.rb, line 15 def meta_tag convert_each_array_to_first_element_on meta_tags end
Private Instance Methods
Source
# File lib/meta_inspector/parsers/meta_tags.rb, line 35 def charset_from_meta_charset parsed.css('meta[charset]')[0].attributes['charset'].value rescue nil end
Source
# File lib/meta_inspector/parsers/meta_tags.rb, line 39 def charset_from_meta_content_type parsed.css("meta[http-equiv='Content-Type']")[0] .attributes['content'].value.split(';')[1].split('=')[1] rescue nil end
Source
# File lib/meta_inspector/parsers/meta_tags.rb, line 58 def convert_each_array_to_first_element_on(hash) hash.each_pair do |k, v| hash[k] = if v.is_a?(Hash) convert_each_array_to_first_element_on(v) elsif v.is_a?(Array) v.first else v end end end