lucid_works 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,8 @@ en:
5
5
  lucid_works:
6
6
  collection:
7
7
  activity:
8
+ one: Activity
9
+ other: Activities
8
10
  type:
9
11
  optimize: Optimize
10
12
  spelling: Spelling
@@ -46,7 +46,7 @@ module LucidWorks
46
46
  end
47
47
 
48
48
  def prime_activities
49
- self.activities!
49
+ self.activities!.sort!{|a,b|a.id <=> b.id}
50
50
  num_created = 0
51
51
  activities_to_return = %w(optimize spelling click autocomplete).map do |type|
52
52
  if act = self.activities.detect{|act| act.type == type}
@@ -1,3 +1,4 @@
1
+ require 'active_support/core_ext/numeric/time.rb'
1
2
  module LucidWorks
2
3
  class Collection < Base
3
4
  class Activity < Base
@@ -17,7 +18,7 @@ module LucidWorks
17
18
  validates_numericality_of :period, :allow_blank => true
18
19
 
19
20
  def t_type
20
- I18n.t(type, :scope => 'activemodel.models.lucid_works.datasource.type')
21
+ I18n.t(type, :scope => 'activemodel.models.lucid_works.collection.activity.type')
21
22
  end
22
23
 
23
24
  def start
@@ -26,8 +27,43 @@ module LucidWorks
26
27
  save
27
28
  end
28
29
 
30
+ def human_readable_period
31
+ case
32
+ when result = exact('weeks', period) then [result, 'weeks']
33
+ when result = exact('days', period) then [result, 'days']
34
+ when hours = exact('hours', period) then [hours, 'hours']
35
+ when period < 1.hours then [1, 'hours']
36
+ else [(period / 1.hours).round, 'hours']
37
+ end
38
+ end
39
+
40
+ def human_readable_period=(params)
41
+ number, type, junk = params
42
+ raise "invalid parameters #{number.class}, #{type.class}, #{junk.nil? ? 'nothing extra' : extra.class}" unless number.is_a?(Fixnum) && type.is_a?(String) && junk.nil?
43
+ raise "invalid parameters #{type}" unless %(hours days weeks).include?(type.to_s)
44
+ number = number.to_i
45
+ self.period = number * 1.send(type).to_i
46
+ [number, type]
47
+ end
48
+
49
+ def ruby_start_time
50
+ Time.iso8601 self.start_time
51
+ end
52
+
53
+ def ruby_start_time=(time_value)
54
+ self.start_time = time_value.iso8601
55
+ end
56
+
29
57
  private
30
58
 
59
+ def exact(interval, period)
60
+ if period % (result = 1.send(interval)) == 0
61
+ period / result
62
+ else
63
+ false
64
+ end
65
+ end
66
+
31
67
  end
32
68
  end
33
69
  end
@@ -1,3 +1,3 @@
1
1
  module LucidWorks
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -83,6 +83,43 @@ describe LucidWorks::Collection::Activity do
83
83
  }.should change(@activity, :history_size).by(1)
84
84
  end
85
85
  end
86
+
87
+ describe "#human_readable_period" do
88
+ it "should return hours if divisible by 1.hours but not by 1.days or 1.weeks" do
89
+ activity = LucidWorks::Collection::Activity.new(:period => 3600*2, :parent => @collection)
90
+ activity.human_readable_period.should == [2, 'hours']
91
+ end
92
+ it "should return nearest hours if not divisible by 1.hours"do
93
+ activity = LucidWorks::Collection::Activity.new(:period => 3600*2.4, :parent => @collection)
94
+ activity.human_readable_period.should == [2, 'hours']
95
+ activity = LucidWorks::Collection::Activity.new(:period => 3600*4.6, :parent => @collection)
96
+ activity.human_readable_period.should == [5, 'hours']
97
+ activity = LucidWorks::Collection::Activity.new(:period => 3600*10.01, :parent => @collection)
98
+ activity.human_readable_period.should == [10, 'hours']
99
+ end
100
+ it "should return 1 hours if < 1.hours"do
101
+ activity = LucidWorks::Collection::Activity.new(:period => 3599, :parent => @collection)
102
+ activity.human_readable_period.should == [1, 'hours']
103
+ end
104
+ it "should return days if divisible by 1.days but not 1.weeks" do
105
+ activity = LucidWorks::Collection::Activity.new(:period => 3600*48, :parent => @collection)
106
+ activity.human_readable_period.should == [2, 'days']
107
+ end
108
+ it "should return weeks if divisible by 1.weeks" do
109
+ activity = LucidWorks::Collection::Activity.new(:period => 3600*24*7, :parent => @collection)
110
+ activity.human_readable_period.should == [1, 'weeks']
111
+ end
112
+ end
113
+
114
+ describe "#human_readable_period=" do
115
+ it "should set correct period if given a number and hours/days/weeks" do
116
+ activity = LucidWorks::Collection::Activity.new(:parent => @collection)
117
+ activity.human_readable_period = [2, 'hours']
118
+ activity.period.should == 3600*2
119
+ activity.human_readable_period = [2, 'days']
120
+ activity.period.should == 3600*2*24
121
+ end
122
+ end
86
123
  end
87
124
  end
88
125
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: lucid_works
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.0
5
+ version: 0.6.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sam Pierson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-25 00:00:00 -07:00
13
+ date: 2011-04-29 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency