Module: PriceHubble::Concern::Attributes::Range

Extended by:
ActiveSupport::Concern
Included in:
PriceHubble::Concern::Attributes
Defined in:
lib/price_hubble/entity/concern/attributes/range.rb

Overview

A separated range typed attribute helper.

Class Method Summary collapse

Class Method Details

.typed_attr_range(name, **_args) ⇒ Object

Register a range attribute.

Parameters:

  • name (Symbol, String)

    the name of the attribute

  • _args (Hash{Symbol => Mixed})

    additional options



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/price_hubble/entity/concern/attributes/range.rb', line 15

def typed_attr_range(name, **_args)
  class_eval "    def \#{name}\n      # We cannot handle nil values\n      return unless @\#{name}\n\n      # Otherwise we assume the hash contains a +lower+ and +upper+\n      # key from which we assemble the range\n      hash = @\#{name}\n      hash[:lower]..hash[:upper]\n    end\n  RUBY\nend\n", __FILE__, __LINE__ + 1