edtf-humanize 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +34 -0
  3. data/lib/edtf-humanize.rb +1 -0
  4. data/lib/edtf/humanize.rb +74 -0
  5. data/lib/edtf/humanize/century.rb +13 -0
  6. data/lib/edtf/humanize/decade.rb +13 -0
  7. data/lib/edtf/humanize/formats.rb +73 -0
  8. data/lib/edtf/humanize/interval.rb +26 -0
  9. data/lib/edtf/humanize/iso_date.rb +13 -0
  10. data/lib/edtf/humanize/season.rb +13 -0
  11. data/lib/edtf/humanize/set.rb +21 -0
  12. data/lib/edtf/humanize/version.rb +5 -0
  13. data/lib/tasks/edtf_humanize_tasks.rake +4 -0
  14. data/test/dummy/README.rdoc +28 -0
  15. data/test/dummy/Rakefile +6 -0
  16. data/test/dummy/app/assets/javascripts/application.js +13 -0
  17. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  18. data/test/dummy/app/controllers/application_controller.rb +5 -0
  19. data/test/dummy/app/helpers/application_helper.rb +2 -0
  20. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  21. data/test/dummy/bin/bundle +3 -0
  22. data/test/dummy/bin/rails +4 -0
  23. data/test/dummy/bin/rake +4 -0
  24. data/test/dummy/bin/setup +29 -0
  25. data/test/dummy/config.ru +4 -0
  26. data/test/dummy/config/application.rb +26 -0
  27. data/test/dummy/config/boot.rb +5 -0
  28. data/test/dummy/config/database.yml +25 -0
  29. data/test/dummy/config/environment.rb +5 -0
  30. data/test/dummy/config/environments/development.rb +41 -0
  31. data/test/dummy/config/environments/production.rb +79 -0
  32. data/test/dummy/config/environments/test.rb +42 -0
  33. data/test/dummy/config/initializers/assets.rb +11 -0
  34. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  35. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  36. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  37. data/test/dummy/config/initializers/inflections.rb +16 -0
  38. data/test/dummy/config/initializers/mime_types.rb +4 -0
  39. data/test/dummy/config/initializers/session_store.rb +3 -0
  40. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  41. data/test/dummy/config/locales/en.yml +23 -0
  42. data/test/dummy/config/routes.rb +56 -0
  43. data/test/dummy/config/secrets.yml +22 -0
  44. data/test/dummy/db/test.sqlite3 +0 -0
  45. data/test/dummy/log/test.log +540 -0
  46. data/test/dummy/public/404.html +67 -0
  47. data/test/dummy/public/422.html +67 -0
  48. data/test/dummy/public/500.html +66 -0
  49. data/test/dummy/public/favicon.ico +0 -0
  50. data/test/edtf_humanize_test.rb +70 -0
  51. data/test/test_helper.rb +19 -0
  52. metadata +175 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e0e270335cf2b7abbc0422aae7201a087a0be8b
4
+ data.tar.gz: bbe083a2e89d792d98d849cc68200f1ee83c2ff2
5
+ SHA512:
6
+ metadata.gz: 44252fe461dcc101dd6bda09cc54d313a5466b295aa0dbdf140e4ffd9269f12c2541a525afe622402891367bbd8d26c4f5a08921d96fdb7c72e6f0230a585cc4
7
+ data.tar.gz: a15d6d76736c69afb1c70bfca8bd3e56ae849f15c916fd3727eb4fd0821fb80252ac46d91f1d5b77ff4ae88cfd98c3f3f3ddad24ef8c92e7e7a7c1c4acde61d4
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'EdtfHumanize'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1 @@
1
+ require 'edtf/humanize'
@@ -0,0 +1,74 @@
1
+ module Edtf
2
+ module Humanize
3
+
4
+ require 'edtf'
5
+
6
+ require 'edtf/humanize/formats'
7
+ require 'edtf/humanize/decade'
8
+ require 'edtf/humanize/century'
9
+ require 'edtf/humanize/season'
10
+ require 'edtf/humanize/interval'
11
+ require 'edtf/humanize/set'
12
+ require 'edtf/humanize/iso_date'
13
+
14
+ EDTF::Decade.include Edtf::Humanize::Decade
15
+ EDTF::Century.include Edtf::Humanize::Century
16
+ EDTF::Season.include Edtf::Humanize::Season
17
+ EDTF::Interval.include Edtf::Humanize::Interval
18
+ EDTF::Set.include Edtf::Humanize::Set
19
+ Date.include Edtf::Humanize::IsoDate
20
+
21
+ def self.configuration
22
+ @configuration ||= Configuration.new
23
+ end
24
+
25
+ def self.configuration=(configuration)
26
+ @configuration = configuration
27
+ end
28
+
29
+ def self.configure
30
+ yield configuration
31
+ end
32
+
33
+ class Configuration
34
+
35
+ attr_accessor :day_precision_strftime_format,
36
+ :month_precision_strftime_format,
37
+ :year_precision_strftime_format,
38
+ :approximate_date_prefix,
39
+ :uncertain_date_suffix,
40
+ :decade_suffix,
41
+ :century_suffix,
42
+ :unspecified_digit_substitute,
43
+ :interval_connector,
44
+ :set_dates_connector,
45
+ :set_last_date_connector,
46
+ :set_two_dates_connector,
47
+ :interval_unspecified_suffix
48
+
49
+ def initialize
50
+ @day_precision_strftime_format = "%B %-d, %Y"
51
+ @month_precision_strftime_format = "%B %Y"
52
+ @year_precision_strftime_format = "%Y"
53
+
54
+ @approximate_date_prefix = "circa "
55
+
56
+ @uncertain_date_suffix = "?"
57
+
58
+ @decade_suffix = "s"
59
+ @century_suffix = "s"
60
+
61
+ @unspecified_digit_substitute = "x"
62
+
63
+ @interval_connector = " to "
64
+ @interval_unspecified_suffix = "s"
65
+
66
+ @set_dates_connector = ", "
67
+ @set_last_date_connector = " or "
68
+ @set_two_dates_connector = " or "
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,13 @@
1
+ module Edtf
2
+ module Humanize
3
+ module Century
4
+
5
+ include Edtf::Humanize::Formats
6
+
7
+ def humanize
8
+ "#{self.begin.year}#{Edtf::Humanize.configuration.century_suffix}"
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Edtf
2
+ module Humanize
3
+ module Decade
4
+
5
+ include Edtf::Humanize::Formats
6
+
7
+ def humanize
8
+ "#{self.begin.year}#{Edtf::Humanize.configuration.decade_suffix}"
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,73 @@
1
+ module Edtf
2
+ module Humanize
3
+ module Formats
4
+
5
+ private
6
+
7
+ def simple_date_format date
8
+ "#{apply_if_unspecified_year(date)}#{apply_if_uncertain(date)}"
9
+ end
10
+
11
+ def date_precision date
12
+ if date.respond_to? :precision
13
+ case date.precision
14
+ when :day # 2010-10-25
15
+ day_precision_format(date)
16
+ when :month # 2010-10
17
+ month_precision_format(date)
18
+ when :year # 2010
19
+ year_precision_format(date)
20
+ end
21
+ else
22
+ date
23
+ end
24
+ end
25
+
26
+ # October 5, 1995
27
+ def day_precision_format date
28
+ date.strftime(Edtf::Humanize.configuration.day_precision_strftime_format)
29
+ end
30
+
31
+ # October 1995
32
+ def month_precision_format date
33
+ date.strftime(Edtf::Humanize.configuration.month_precision_strftime_format)
34
+ end
35
+
36
+ # 1995
37
+ def year_precision_format date
38
+ date.strftime(Edtf::Humanize.configuration.year_precision_strftime_format)
39
+ end
40
+
41
+ # '1990~' => circa 1990
42
+ def apply_if_approximate date
43
+ if date.respond_to? :approximate?
44
+ if date.approximate?
45
+ Edtf::Humanize.configuration.approximate_date_prefix
46
+ end
47
+ end
48
+ end
49
+
50
+ # '1990?' => 1990?
51
+ def apply_if_uncertain date
52
+ if date.respond_to? :uncertain?
53
+ if date.uncertain?
54
+ Edtf::Humanize.configuration.uncertain_date_suffix
55
+ end
56
+ end
57
+ end
58
+
59
+ # '198u' => 198x
60
+ def apply_if_unspecified_year date
61
+ display = date_precision(date)
62
+ if date.respond_to? :unspecified?
63
+ if date.unspecified? :year
64
+ year_substitute = date.year_precision.edtf.gsub(/u/, Edtf::Humanize.configuration.unspecified_digit_substitute)
65
+ display.gsub!("#{date.year}", year_substitute)
66
+ end
67
+ end
68
+ display
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,26 @@
1
+ module Edtf
2
+ module Humanize
3
+ module Interval
4
+
5
+ include Edtf::Humanize::Formats
6
+
7
+ def humanize
8
+ "#{apply_if_approximate(self.from)}#{simple_date_format(self.from)}#{Edtf::Humanize.configuration.interval_connector}#{simple_date_format(self.to)}"
9
+ end
10
+
11
+ private
12
+
13
+ # '198u/199u' => 1980s to 1990s
14
+ def apply_if_unspecified_year date
15
+ display = date_precision(date)
16
+ if date.respond_to? :unspecified?
17
+ if date.unspecified? :year
18
+ display << Edtf::Humanize.configuration.interval_unspecified_suffix
19
+ end
20
+ end
21
+ display
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ module Edtf
2
+ module Humanize
3
+ module IsoDate
4
+
5
+ include Edtf::Humanize::Formats
6
+
7
+ def humanize
8
+ "#{apply_if_approximate(self)}#{simple_date_format(self)}"
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Edtf
2
+ module Humanize
3
+ module Season
4
+
5
+ include Edtf::Humanize::Formats
6
+
7
+ def humanize
8
+ "#{apply_if_approximate(self)}#{self.season} #{self.year}#{apply_if_uncertain(self)}"
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module Edtf
2
+ module Humanize
3
+ module Set
4
+
5
+ include Edtf::Humanize::Formats
6
+
7
+ def humanize
8
+ display = []
9
+ self.entries.each do |date|
10
+ display << "#{apply_if_approximate(date)}#{simple_date_format(date)}"
11
+ end
12
+ display.to_sentence(
13
+ words_connector: Edtf::Humanize.configuration.set_dates_connector,
14
+ last_word_connector: Edtf::Humanize.configuration.set_last_date_connector,
15
+ two_words_connector: Edtf::Humanize.configuration.set_two_dates_connector
16
+ )
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module Edtf
2
+ module Humanize
3
+ VERSION = "0.0.3"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :edtf_humanize do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end