Module: GoogleSpreadsheets::Enhanced::NamespacePreservable

Extended by:
ActiveSupport::Concern
Included in:
Row, Spreadsheet, Worksheet
Defined in:
lib/google_spreadsheets/enhanced/namespace_preservable.rb,
lib/google_spreadsheets/enhanced/namespace_preservable/rexml_parser.rb,
lib/google_spreadsheets/enhanced/namespace_preservable/nokogiri_parser.rb

Defined Under Namespace

Modules: ClassMethods, NokogiriParser, RexmlParser Classes: Format

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_symbol, *arguments) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/google_spreadsheets/enhanced/namespace_preservable.rb', line 79

def method_missing(method_symbol, *arguments)
  method_name = method_symbol.to_s

  if (matches = method_name.match(/(=)$/)) && attributes.include?("gsx:#{matches.pre_match}")
    attributes["gsx:#{matches.pre_match}"] = arguments.first
  elsif (matches = method_name.match(/(\?)$/)) && attributes.include?("gsx:#{matches.pre_match}")
    attributes["gsx:#{matches.pre_match}"]
  elsif attributes.include?("gsx:#{method_name}")
    attributes["gsx:#{method_name}"]
  else
    super
  end
end

Instance Method Details

#aliased_attributesObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/google_spreadsheets/enhanced/namespace_preservable.rb', line 56

def aliased_attributes
  aliased = _attr_aliases.invert
  gsx_attributes = self.attributes.keys.map do |attr|
    if matches = attr.match(/^(gsx:)/)
      (aliased[matches.post_match] || matches.post_match).to_s
    else
      nil
    end
  end.compact
  (self.class.known_attributes + gsx_attributes - self.class._ignore_attributes).uniq
end

#all_values_empty?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/google_spreadsheets/enhanced/namespace_preservable.rb', line 68

def all_values_empty?
  self.attributes.select{|k, v| k.to_s.start_with?('gsx:') && k.to_s != 'gsx:id' }.values.all?{|v| v == '' }
end

#respond_to?(method, include_priv = false) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
76
77
# File 'lib/google_spreadsheets/enhanced/namespace_preservable.rb', line 72

def respond_to?(method, include_priv = false)
  method_name = method.to_s
  ((matches = method_name.match(/(=|\?)$/)) && attributes.include?("gsx:#{matches.pre_match}")) ||
  attributes.include?("gsx:#{method_name}") ||
  super
end