Class: Ehbrs::Tools::Observers::Base

Inherits:
Object
  • Object
show all
Includes:
EacRubyUtils::Listable
Defined in:
lib/ehbrs/tools/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.



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

def blank_value
  @blank_value
end

#last_check_timeObject (readonly)

Returns the value of attribute last_check_time.



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

def last_check_time
  @last_check_time
end

#recordsObject (readonly)

Returns the value of attribute records.



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

def records
  @records
end

Instance Method Details

#changing_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


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

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



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

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



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

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

#last_valueObject



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

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