Class: GitFit::Util::Tally

Inherits:
Object
  • Object
show all
Defined in:
lib/git_fit/util/tally.rb

Constant Summary collapse

DIGITS =
%w[          ].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(count = 0) ⇒ Tally

Returns a new instance of Tally.



12
13
14
# File 'lib/git_fit/util/tally.rb', line 12

def initialize(count = 0)
  @value = count
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



10
11
12
# File 'lib/git_fit/util/tally.rb', line 10

def value
  @value
end

Instance Method Details

#<(other) ⇒ Object



38
39
40
# File 'lib/git_fit/util/tally.rb', line 38

def <(other)
  to_i < other.to_i
end

#==(other) ⇒ Object



34
35
36
# File 'lib/git_fit/util/tally.rb', line 34

def ==(other)
  to_i == other.to_i
end

#add(n = 1) ⇒ Object



16
17
18
19
# File 'lib/git_fit/util/tally.rb', line 16

def add(n = 1)
  @value += n
  self
end

#inspectObject



51
52
53
# File 'lib/git_fit/util/tally.rb', line 51

def inspect
  "#<#{self.class.name} value=#{@value}>"
end

#reset(count = 0) ⇒ Object



21
22
23
24
# File 'lib/git_fit/util/tally.rb', line 21

def reset(count = 0)
  @value = count
  self
end

#to_iObject



26
27
28
# File 'lib/git_fit/util/tally.rb', line 26

def to_i
  @value.to_i
end

#to_intObject



30
31
32
# File 'lib/git_fit/util/tally.rb', line 30

def to_int
  to_i
end

#to_s(format: :chinese) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/git_fit/util/tally.rb', line 42

def to_s(format: :chinese)
  case format
  when :arabic then @value.to_s
  else to_chinese
  end
rescue StandardError
  @value.to_s
end