Module: Axlsx::Accessors::ClassMethods

Defined in:
lib/axlsx/util/accessors.rb

Overview

Defines the class level xxx_attr_accessor methods

Instance Method Summary collapse

Instance Method Details

#boolean_attr_accessor(*symbols) ⇒ Object

Creates on or more boolean validated attr_accessors names of the attributes you will add to your class.

Parameters:

  • symbols (Array)

    An array of symbols representing the



43
44
45
# File 'lib/axlsx/util/accessors.rb', line 43

def boolean_attr_accessor(*symbols)
  validated_attr_accessor(symbols, :validate_boolean)
end

#float_attr_accessor(*symbols) ⇒ Object

Creates one or more float (double?) attr_accessors names of the attributes you will add to your class

Parameters:

  • symbols (Array)

    An array of symbols representing the



36
37
38
# File 'lib/axlsx/util/accessors.rb', line 36

def float_attr_accessor(*symbols)
  validated_attr_accessor(symbols, :validate_float)
end

#string_attr_accessor(*symbols) ⇒ Object

Creates one or more string validated attr_accessors names of the attributes you will add to your class.

Parameters:

  • symbols (Array)

    An array of symbols representing the



22
23
24
# File 'lib/axlsx/util/accessors.rb', line 22

def string_attr_accessor(*symbols)
  validated_attr_accessor(symbols, :validate_string)
end

#unsigned_int_attr_accessor(*symbols) ⇒ Object

Creates one or more usigned integer attr_accessors names of the attributes you will add to your class

Parameters:

  • symbols (Array)

    An array of symbols representing the



29
30
31
# File 'lib/axlsx/util/accessors.rb', line 29

def unsigned_int_attr_accessor(*symbols)
  validated_attr_accessor(symbols, :validate_unsigned_int)
end

#validated_attr_accessor(symbols, validator) ⇒ Object

Creates the reader and writer access methods validating assignation.

Parameters:

  • symbols (Array<Symbol, String>)

    The names of the attributes to create

  • validator (Symbol|String)

    The axlsx validation method to use when

See Also:

  • Axlsx::Accessors::ClassMethods.lib/axlsx/util/validatorslib/axlsx/util/validators.rb


52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/axlsx/util/accessors.rb', line 52

def validated_attr_accessor(symbols, validator)
  symbols.each do |symbol|
    attr_reader symbol

    module_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
      def #{symbol}=(value)      # def name=(value)
        Axlsx.#{validator} value #   Axlsx.validate_string value
        @#{symbol} = value       #   @name = value
      end                        # end
    RUBY_EVAL
  end
end