Permalink
Browse files

period attribute -> name

  • Loading branch information...
1 parent cbc7202 commit dfd09e59dd9cbe6bdae800dba8510b11aac40043 @blahed committed Jan 31, 2013
Showing with 18 additions and 18 deletions.
  1. +1 −1 lib/von/counters/period.rb
  2. +12 −12 lib/von/period.rb
  3. +5 −5 test/config_test.rb
@@ -46,7 +46,7 @@ def count(period)
counts = []
this_period = nil
- _period = @periods.select { |p| p.period == period }.first
+ _period = @periods.select { |p| p.name == period }.first
_period.length.times do |i|
this_period = _period.prev(i)
View
@@ -11,7 +11,7 @@ class Period
AVAILABLE_PERIODS = PERIOD_MAPPING.keys
AVAILABLE_TIME_UNITS = PERIOD_MAPPING.values
- attr_reader :period
+ attr_reader :name
attr_reader :length
attr_reader :format
@@ -20,37 +20,37 @@ class Period
# period - the time period one of AVAILABLE_PERIODS
# length - length of period
def initialize(period, length = nil)
- period = period.to_sym
- if AVAILABLE_PERIODS.include?(period)
- @period = period
- elsif AVAILABLE_TIME_UNITS.include?(period)
- @period = PERIOD_MAPPING.invert[period]
+ name = period.to_sym
+ if AVAILABLE_PERIODS.include?(name)
+ @name = name
+ elsif AVAILABLE_TIME_UNITS.include?(name)
+ @name = PERIOD_MAPPING.invert[name]
else
raise ArgumentError, "`#{period}' is not a valid period"
end
@length = length
- @format = Von.config.send(:"#{@period}_format")
+ @format = Von.config.send(:"#{@name}_format")
end
# TODO: take this out, dirty
def to_s
- @period.to_s
+ @name.to_s
end
# Returns a Symbol representing the time unit
# for the current period.
def time_unit
- @time_unit ||= PERIOD_MAPPING[@period]
+ @time_unit ||= PERIOD_MAPPING[@name]
end
# Returns True or False if the period is hourly
def hours?
- @period == :hourly
+ @name == :hourly
end
# Returns True or False if the period is minutely
def minutes?
- @period == :minutely
+ @name == :minutely
end
def beginning(time)
@@ -68,7 +68,7 @@ def prev(unit = 1)
def timestamp
beginning(Time.now).strftime(format)
end
-
+
def self.unit_to_period(time_unit)
PERIOD_MAPPING.invert[time_unit]
end
View
@@ -24,9 +24,9 @@
end
Von.config.periods[:bar].length.must_equal 2
- Von.config.periods[:bar].first.period.must_equal :monthly
+ Von.config.periods[:bar].first.name.must_equal :monthly
Von.config.periods[:bar].first.length.must_equal 3
- Von.config.periods[:bar].last.period.must_equal :daily
+ Von.config.periods[:bar].last.name.must_equal :daily
Von.config.periods[:bar].last.length.must_equal 6
end
@@ -37,11 +37,11 @@
end
Von.config.bests[:bar].first.must_be_instance_of Von::Period
- Von.config.bests[:bar].first.period.must_equal :daily
+ Von.config.bests[:bar].first.name.must_equal :daily
Von.config.bests[:foo].first.must_be_instance_of Von::Period
- Von.config.bests[:foo].first.period.must_equal :monthly
+ Von.config.bests[:foo].first.name.must_equal :monthly
Von.config.bests[:foo].last.must_be_instance_of Von::Period
- Von.config.bests[:foo].last.period.must_equal :yearly
+ Von.config.bests[:foo].last.name.must_equal :yearly
end
end

0 comments on commit dfd09e5

Please sign in to comment.