Class: Ehbrs::Observers::Base

Inherits:
Object
  • Object
show all
Includes:
EacRubyUtils::Listable
Defined in:
lib/ehbrs/observers/base.rb

Direct Known Subclasses

WithPersistence

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#blank_valueObject (readonly)

Returns the value of attribute blank_value.



12
13
14
# File 'lib/ehbrs/observers/base.rb', line 12

def blank_value
  @blank_value
end

#last_check_timeObject (readonly)

Returns the value of attribute last_check_time.



12
13
14
# File 'lib/ehbrs/observers/base.rb', line 12

def last_check_time
  @last_check_time
end

#recordsObject (readonly)

Returns the value of attribute records.



12
13
14
# File 'lib/ehbrs/observers/base.rb', line 12

def records
  @records
end

Instance Method Details

#changing_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/ehbrs/observers/base.rb', line 28

def changing_value?(value)
  records.if_present(true) do
    last_value.if_present(value.present?) { |v| v != value }
  end
end

#check(value, date = ::Time.required_zone.now) ⇒ Object



23
24
25
26
# File 'lib/ehbrs/observers/base.rb', line 23

def check(value, date = ::Time.required_zone.now)
  @last_check_time = date
  send("check_with_blank_value_#{blank_value}", value, date)
end

#last_change_timeObject



34
35
36
# File 'lib/ehbrs/observers/base.rb', line 34

def last_change_time
  records.last.if_present(&:time)
end

#last_valueObject



38
39
40
# File 'lib/ehbrs/observers/base.rb', line 38

def last_value
  records.last.if_present(&:value)
end