chronicle 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,9 +2,7 @@ Chronicle
2
2
  =========
3
3
 
4
4
  Chronicle groups collections of ruby objects into time periods.
5
- It uses [Chronic](https://github.com/mojombo/chronic/) to parse natural language date strings
6
- and [ActiveSupport::OrderedHash](http://apidock.com/rails/ActiveSupport/OrderedHash)
7
- to preserve the hash order.
5
+ It uses [Chronic](https://github.com/mojombo/chronic/) to parse natural language date strings.
8
6
 
9
7
  ```ruby
10
8
  # Before:
@@ -20,7 +18,9 @@ to preserve the hash order.
20
18
  }
21
19
  ```
22
20
 
23
- An example UI using Chronicle:
21
+ Chronicle was created for [Sniphr](http://sniphr.com), a pet project of mine that makes
22
+ bookmarking awesome. I wanted to reduce UI chatter by displaying a minimal timeline
23
+ beside the content, instead of a timestamp under every element. Here's what it looks like:
24
24
 
25
25
  [ !["Chronicle on Sniphr"](http://f.cl.ly/items/2I2q0P0w2Z2r0D0d390D/chronicle.png "Chronicle on Sniphr") ](http://sniphr.com "Sniphr")
26
26
 
@@ -29,6 +29,7 @@ Installation
29
29
 
30
30
  ```ruby
31
31
  # Put this in your Gemfile and smoke it.
32
+ # Ruby 1.9 or greater is required, because chronicle relies on ordered hashes.
32
33
  gem 'chronicle'
33
34
  ```
34
35
 
data/chronicle.gemspec CHANGED
@@ -24,5 +24,4 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency 'autotest'
25
25
 
26
26
  s.add_runtime_dependency "chronic"
27
- s.add_dependency 'rails'
28
27
  end
data/lib/chronicle.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'chronic'
3
- require 'active_support/all' # OrderedHash
4
3
  require 'chronicle'
5
4
 
6
5
  module Chronicle
@@ -56,7 +55,7 @@ module Chronicle
56
55
  ]
57
56
  end
58
57
 
59
- class ChronicleHash < ActiveSupport::OrderedHash
58
+ class ChronicleHash < Hash
60
59
 
61
60
  def initialize(collection, options)
62
61
 
@@ -73,7 +72,7 @@ module Chronicle
73
72
  # Sort eras oldest to newest
74
73
  eras = eras.sort_by {|era| Chronic.parse(era) }
75
74
 
76
- # Initialize all OrderedHash keys chronologically (newest to oldest)
75
+ # Initialize all hash keys chronologically (newest to oldest)
77
76
  eras.reverse.each {|era| self[era] = [] }
78
77
 
79
78
  # Find the oldest era in which each object was created
@@ -83,7 +82,7 @@ module Chronicle
83
82
  end
84
83
 
85
84
  # Remove keys for empty eras
86
- self.keys.each {|k| self.delete(k) if self[k].blank? }
85
+ self.keys.each {|k| self.delete(k) if self[k].empty? }
87
86
 
88
87
  self
89
88
  end
@@ -1,3 +1,3 @@
1
1
  module Chronicle
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -3,12 +3,15 @@ require 'spec_helper'
3
3
  describe Chronicle do
4
4
 
5
5
  before(:each) do
6
+ minute = 60
7
+ hour = minute*60
8
+ day = hour*24
6
9
  @things = [
7
- double("thing", :created_at => 39.days.ago),
8
- double("thing", :created_at => 8.days.ago),
9
- double("thing", :created_at => 9.days.ago),
10
- double("thing", :created_at => 3.days.ago),
11
- double("thing", :created_at => 10.minutes.ago),
10
+ double("thing", :created_at => Time.now - 39*day),
11
+ double("thing", :created_at => Time.now - 8*day),
12
+ double("thing", :created_at => Time.now - 9*day),
13
+ double("thing", :created_at => Time.now - 3*day),
14
+ double("thing", :created_at => Time.now - 10*minute),
12
15
  double("thing", :created_at => Time.now)
13
16
  ]
14
17
 
@@ -16,7 +19,7 @@ describe Chronicle do
16
19
  end
17
20
 
18
21
  it "doesn't have any empty eras" do
19
- @chronicle.values.all? {|v| v.present? }.should == true
22
+ @chronicle.values.all? {|v| !v.empty? }.should == true
20
23
  end
21
24
 
22
25
  it "sorts era keys from newest to oldest" do
@@ -36,7 +39,7 @@ describe Chronicle do
36
39
 
37
40
  it "accounts for objects that were just created" do
38
41
  now = @chronicle['just now']
39
- now.should_not be_blank
42
+ now.should_not be_empty
40
43
  now.should be_an(Array)
41
44
  now.first.should == @things.last
42
45
  end
@@ -62,12 +65,15 @@ describe Chronicle do
62
65
  context "custom date attribute" do
63
66
 
64
67
  before(:each) do
68
+ minute = 60
69
+ hour = minute*60
70
+ day = hour*24
65
71
  @things = [
66
- double("thing", :updated_at => 369.days.ago, :created_at => nil),
67
- double("thing", :updated_at => 9.days.ago, :created_at => nil),
68
- double("thing", :updated_at => 8.days.ago, :created_at => nil),
69
- double("thing", :updated_at => 3.days.ago, :created_at => nil),
70
- double("thing", :updated_at => 10.minutes.ago, :created_at => nil),
72
+ double("thing", :updated_at => Time.now - 369*day, :created_at => nil),
73
+ double("thing", :updated_at => Time.now - 9*day, :created_at => nil),
74
+ double("thing", :updated_at => Time.now - 8*day, :created_at => nil),
75
+ double("thing", :updated_at => Time.now - 3*day, :created_at => nil),
76
+ double("thing", :updated_at => Time.now - 10*minute, :created_at => nil),
71
77
  double("thing", :updated_at => Time.now, :created_at => nil)
72
78
  ]
73
79
  end
data/spec/spec_helper.rb CHANGED
@@ -1,14 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
-
4
3
  require 'chronicle'
5
4
  include Chronicle
6
5
 
7
- require 'active_support/all' # to get methods like blank? and starts_with?
8
-
9
- # include ActionView::Helpers
10
- include ActiveSupport
11
-
12
6
  RSpec.configure do |config|
13
7
  # some (optional) config here
14
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chronicle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-27 00:00:00.000000000 Z
12
+ date: 2012-02-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hoe
16
- requirement: &70113761128700 !ruby/object:Gem::Requirement
16
+ requirement: &70345089392060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70113761128700
24
+ version_requirements: *70345089392060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70113761128200 !ruby/object:Gem::Requirement
27
+ requirement: &70345089391560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.8.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70113761128200
35
+ version_requirements: *70345089391560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: autotest
38
- requirement: &70113761127780 !ruby/object:Gem::Requirement
38
+ requirement: &70345089391140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70113761127780
46
+ version_requirements: *70345089391140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: chronic
49
- requirement: &70113761127320 !ruby/object:Gem::Requirement
49
+ requirement: &70345089390680 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,18 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70113761127320
58
- - !ruby/object:Gem::Dependency
59
- name: rails
60
- requirement: &70113761126900 !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
66
- type: :runtime
67
- prerelease: false
68
- version_requirements: *70113761126900
57
+ version_requirements: *70345089390680
69
58
  description: Chronicle groups collections of ruby objects into time periods.
70
59
  email:
71
60
  - zeke@sikelianos.com