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.



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

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

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/git_fit/util/tally.rb', line 8

def value
  @value
end

Instance Method Details

#<(other) ⇒ Object



36
37
38
# File 'lib/git_fit/util/tally.rb', line 36

def <(other)
  to_i < other.to_i
end

#==(other) ⇒ Object



32
33
34
# File 'lib/git_fit/util/tally.rb', line 32

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

#add(n = 1) ⇒ Object



14
15
16
17
# File 'lib/git_fit/util/tally.rb', line 14

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

#inspectObject



49
50
51
# File 'lib/git_fit/util/tally.rb', line 49

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

#reset(count = 0) ⇒ Object



19
20
21
22
# File 'lib/git_fit/util/tally.rb', line 19

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

#to_iObject



24
25
26
# File 'lib/git_fit/util/tally.rb', line 24

def to_i
  @value.to_i
end

#to_intObject



28
29
30
# File 'lib/git_fit/util/tally.rb', line 28

def to_int
  to_i
end

#to_s(format: :chinese) ⇒ Object



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

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