time_compact 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a07ad5487258701576985039433534a971cd7886
4
- data.tar.gz: d9dfa3fbf7af561adf42b7827c2e808a40f4c0fc
3
+ metadata.gz: 81ad0a9403e46694eda26d158cef5d9aa76b2ee7
4
+ data.tar.gz: fddc40df215da1c9748201616ffc610ee0450c17
5
5
  SHA512:
6
- metadata.gz: bec71f0877f0fd18352da5daa7c164ea9bef8e75c66f154cda30e6225ca51b4e400b66bdab699527aa34cc4617ced136fc619ca1837a18372df5ae2646140dcf
7
- data.tar.gz: b42c4de394bc46f6855622d4901b1d0b7e1f454355bf749946a9ceb99bf15f3475537e6299f7813a55d31a74d86759d5e0b10f3d769b07dcd8aa243de6d72845
6
+ metadata.gz: fccd9c748f371cbae30d3d66913db61512ece8b54ac853f6b7429f040a106b641e0b647a51ccbb908f31a59a32c0022b34e2d1d86e3636e632e37c172d77ae4e
7
+ data.tar.gz: b511b5bdb40bf03f42c15969dcc561eb905f554716a489bded1ace4268ea513f7675493c051bcca8c6ce9032c2ca44e2bc38a38b5150496f3932ed415b567bb3
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.2
6
+ - jruby-1.7.12
7
+ - rbx-2.2.7
8
+ - ruby-head
9
+ - jruby-head
10
+
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: ruby-head
14
+ - rvm: jruby-head
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # TimeCompact
2
2
 
3
+ ![TravisCI Build Status](https://secure.travis-ci.org/komagata/time_compact.png)
4
+
3
5
  Displays time compactly.
4
6
 
5
7
  for example:
@@ -1,6 +1,6 @@
1
- module TimeCompact
1
+ module TimeCompact
2
2
  class Railtie < ::Rails::Railtie
3
- initializer 'time_compact' do |app|
3
+ initializer 'time_compact' do |app|
4
4
  ActiveSupport.on_load(:action_view) do
5
5
  ActionView::Base.send :include, ::TimeCompact
6
6
  end
@@ -1,3 +1,3 @@
1
1
  module TimeCompact
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/time_compact.rb CHANGED
@@ -4,35 +4,28 @@ require 'i18n'
4
4
  require 'yaml'
5
5
 
6
6
  module TimeCompact
7
- LOCALE_DIR = File.expand_path('../../locale', __FILE__)
8
-
9
7
  def time_compact(time, now = Time.now)
8
+ locale_dir = File.expand_path('../../locale', __FILE__)
10
9
  I18n.enforce_available_locales = true
11
- I18n.load_path += Dir[LOCALE_DIR + '/*.yml']
10
+ I18n.load_path += Dir["#{locale_dir}/*.yml"]
11
+ messages = I18n.t('time_compact')
12
12
 
13
13
  if time.year == now.year
14
14
  if time.month == now.month
15
15
  if time.day == now.day
16
16
  if time.hour == now.hour
17
- time.strftime(fetch_locale('same_hour'))
17
+ time.strftime(messages[:same_hour])
18
18
  else
19
- time.strftime(fetch_locale('same_day'))
19
+ time.strftime(messages[:same_day])
20
20
  end
21
21
  else
22
- time.strftime(fetch_locale('same_month'))
22
+ time.strftime(messages[:same_month])
23
23
  end
24
24
  else
25
- time.strftime(fetch_locale('same_year'))
25
+ time.strftime(messages[:same_year])
26
26
  end
27
27
  else
28
- time.strftime(fetch_locale('other'))
28
+ time.strftime(messages[:other])
29
29
  end
30
30
  end
31
-
32
- private
33
-
34
- def fetch_locale(name)
35
- yml = YAML.load_file("#{LOCALE_DIR}/#{I18n.locale}.yml")
36
- yml[I18n.locale.to_s]['time_compact'][name]
37
- end
38
31
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'minitest/autorun'
2
3
  require 'minitest/unit'
3
4
  require_relative '../lib/time_compact'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_compact
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Komagata
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
+ - ".travis.yml"
77
78
  - Gemfile
78
79
  - LICENSE.txt
79
80
  - README.md