gyomu_ruby 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
- # Specify your gem's dependencies in gyomu_ruby.gemspec
4
3
  gemspec
data/HISTORY.md ADDED
@@ -0,0 +1,11 @@
1
+ # Version 0.0.4
2
+
3
+ * added Integer#ceil(offset), Integer#floor(offset)
4
+
5
+ # Version 0.0.3
6
+
7
+ * added GyomuRuby::AWS::FileBucket
8
+
9
+ # Version 0.0.1
10
+
11
+ * initial release
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # GyomuRuby
data/Rakefile CHANGED
@@ -1,2 +1,11 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake'
5
+ require 'rspec/core/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.pattern = "spec/**/*_spec.rb"
9
+ end
10
+
11
+ task :default => [:spec]
data/gyomu_ruby.gemspec CHANGED
@@ -16,4 +16,9 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
+
20
+ s.add_dependency("activesupport", [">= 3.0"])
21
+ s.add_dependency("aws-s3", [">= 0"])
22
+
23
+ s.add_development_dependency "rspec", [">= 2.0"]
19
24
  end
data/lib/gyomu_ruby.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  # coding: utf-8
2
2
  require 'gyomu_ruby/core_ext/time'
3
+ require 'gyomu_ruby/amazon_web_service/file_bucket'
3
4
  require 'gyomu_ruby/ordinary_system_development'
@@ -0,0 +1,74 @@
1
+ # coding: utf-8
2
+ require 'securerandom'
3
+
4
+ module GyomuRuby
5
+ module AmazonWebService
6
+ class FileBucket
7
+ attr_accessor :backend
8
+
9
+ extend Forwardable
10
+ def_delegators :backend, *%w[bucket get delete]
11
+
12
+ def initialize(bucket = 'bucket')
13
+ @backend = Rails.env.production? || Rails.env.staging? ? RichMan.new(bucket) : PoorMan.new(bucket)
14
+ end
15
+
16
+ def put(io)
17
+ "#{Time.now.strftime('%Y%m%d%H%M')}_#{SecureRandom.hex(5)}".tap do |key|
18
+ @backend.put(key, io)
19
+ end
20
+ end
21
+
22
+ class PoorMan
23
+ require 'fileutils'
24
+
25
+ attr_reader :bucket
26
+
27
+ def initialize(bucket)
28
+ @bucket = bucket
29
+ path = Rails.root.join('tmp', @bucket)
30
+ FileUtils.mkdir_p path unless FileTest.exist? path
31
+ end
32
+
33
+ def put(key, io)
34
+ File.open(Rails.root.join('tmp', @bucket, key), 'w:BINARY') {|f| f.write(io.read)}
35
+ end
36
+
37
+ def get(key)
38
+ File.open(Rails.root.join('tmp', @bucket, key), 'r:BINARY') {|f| f.read }
39
+ end
40
+
41
+ def delete(key)
42
+ !!FileUtils.rm_r(Rails.root.join('tmp', @bucket, key))
43
+ end
44
+ end
45
+
46
+ class RichMan
47
+ require 'aws/s3'
48
+
49
+ attr_reader :bucket
50
+
51
+ def initialize(bucket)
52
+ @bucket = bucket
53
+ ::AWS::S3::Bucket.find(@bucket)
54
+ rescue ::AWS::S3::NoSuchBucket
55
+ ::AWS::S3::Bucket.create(@bucket)
56
+ end
57
+
58
+ def put(key, io)
59
+ ::AWS::S3::S3Object.store(key, io, @bucket)
60
+ end
61
+
62
+ def get(key)
63
+ ::AWS::S3::S3Object.value(key, @bucket) rescue nil
64
+ end
65
+
66
+ def delete(key)
67
+ ::AWS::S3::S3Object.delete(key, @bucket) rescue false
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ AWS = AmazonWebService
74
+ end
@@ -0,0 +1 @@
1
+ require 'gyomu_ruby/core_ext/integer/round'
@@ -0,0 +1,9 @@
1
+ class Integer
2
+ def ceil(offset)
3
+ ((self + offset) * Rational(1, offset)).ceil * offset - offset
4
+ end
5
+
6
+ def floor(offset)
7
+ (self * Rational(1, offset)).floor * offset
8
+ end
9
+ end
@@ -4,4 +4,3 @@ require 'gyomu_ruby/core_ext/time/biz_year'
4
4
  Time.class_eval do
5
5
  include GyomuRuby::CoreExt::Time::BizYear
6
6
  end
7
-
@@ -5,7 +5,7 @@ module GyomuRuby
5
5
  module BizYear
6
6
  def biz_year(boundary_mon = 4, boundary_day = 1)
7
7
  now = self
8
- if (now.month < boundary_mon) || (now.month == boundary_day && now.day == boundary_mon)
8
+ if (now.month < boundary_mon) || (now.month == boundary_mon && now.day < boundary_day)
9
9
  now.year - 1
10
10
  else
11
11
  now.year
@@ -24,4 +24,3 @@ module GyomuRuby
24
24
  end
25
25
  end
26
26
  end
27
-
@@ -19,7 +19,7 @@ class Forgery::JaName < Forgery
19
19
  end
20
20
 
21
21
  def self.last_name_with_kana
22
- dictionaries[:ja_last_names].random
22
+ dictionaries[:ja_last_names].sample
23
23
  end
24
24
 
25
25
  def self.first_name
@@ -27,14 +27,14 @@ class Forgery::JaName < Forgery
27
27
  end
28
28
 
29
29
  def self.first_name_with_kana
30
- [dictionaries[:ja_male_first_names], dictionaries[:ja_female_first_names]].random.random
30
+ [dictionaries[:ja_male_first_names], dictionaries[:ja_female_first_names]].sample.sample
31
31
  end
32
32
 
33
33
  def self.male_first_name_with_kana
34
- dictionaries[:ja_male_first_names].random
34
+ dictionaries[:ja_male_first_names].sample
35
35
  end
36
36
 
37
37
  def self.female_first_name_with_kana
38
- dictionaries[:ja_female_first_names].random
38
+ dictionaries[:ja_female_first_names].sample
39
39
  end
40
40
  end
@@ -1,4 +1,4 @@
1
- # coding: us-ascii
1
+ # coding: utf-8
2
2
 
3
3
  module GyomuRuby
4
4
  module OrdinarySystemDevelopment
@@ -1,3 +1,3 @@
1
1
  module GyomuRuby
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'gyomu_ruby/core_ext/integer'
3
+
4
+ describe Integer, 'gyomu_ruby extentions' do
5
+ describe '#ceil' do
6
+ it { 101.ceil(50).should == 150 }
7
+ it { 151.ceil(50).should == 200 }
8
+ it { 121.ceil(3).should == 123 }
9
+ it { 123.ceil(3).should == 123 }
10
+ end
11
+
12
+ describe '#floor' do
13
+ it { 101.floor(50).should == 100 }
14
+ it { 151.floor(50).should == 150 }
15
+ it { 121.floor(3).should == 120 }
16
+ it { 123.floor(3).should == 123 }
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'gyomu_ruby/core_ext/time'
3
+
4
+ describe Time, 'gyomu_ruby extentions' do
5
+ describe '#biz_year' do
6
+ context 'default boundary' do
7
+ specify { Time.local(2011, 4, 1).biz_year.should == 2011 }
8
+ specify { Time.local(2011,12,31).biz_year.should == 2011 }
9
+ specify { Time.local(2012, 1, 1).biz_year.should == 2011 }
10
+ specify { Time.local(2012, 3,31).biz_year.should == 2011 }
11
+ end
12
+
13
+ context 'custom boundary at 4/2' do
14
+ specify { Time.local(2011, 4, 1).biz_year(4, 2).should == 2010 }
15
+ specify { Time.local(2011, 4, 2).biz_year(4, 2).should == 2011 }
16
+ end
17
+
18
+ context 'custom boundary at 3/31' do
19
+ specify { Time.local(2011, 3,30).biz_year(3, 31).should == 2010 }
20
+ specify { Time.local(2011, 3,31).biz_year(3, 31).should == 2011 }
21
+ specify { Time.local(2011, 4, 1).biz_year(3, 31).should == 2011 }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1 @@
1
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gyomu_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,9 +9,41 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-04-22 00:00:00.000000000 +09:00
13
- default_executable:
14
- dependencies: []
12
+ date: 2012-02-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &70139244869760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70139244869760
25
+ - !ruby/object:Gem::Dependency
26
+ name: aws-s3
27
+ requirement: &70139244867040 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70139244867040
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70139241111060 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '2.0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70139241111060
15
47
  description: GyomuRuby
16
48
  email:
17
49
  - rubyagile@qwik.tky.esm.co.jp
@@ -21,9 +53,14 @@ extra_rdoc_files: []
21
53
  files:
22
54
  - .gitignore
23
55
  - Gemfile
56
+ - HISTORY.md
57
+ - README.md
24
58
  - Rakefile
25
59
  - gyomu_ruby.gemspec
26
60
  - lib/gyomu_ruby.rb
61
+ - lib/gyomu_ruby/amazon_web_service/file_bucket.rb
62
+ - lib/gyomu_ruby/core_ext/integer.rb
63
+ - lib/gyomu_ruby/core_ext/integer/round.rb
27
64
  - lib/gyomu_ruby/core_ext/time.rb
28
65
  - lib/gyomu_ruby/core_ext/time/biz_year.rb
29
66
  - lib/gyomu_ruby/forgery/dictionaries/ja_female_first_names
@@ -37,7 +74,9 @@ files:
37
74
  - lib/gyomu_ruby/version.rb
38
75
  - masters/ext_tel_numbers.csv
39
76
  - masters/prefectures.csv
40
- has_rdoc: true
77
+ - spec/core_ext/integer_spec.rb
78
+ - spec/core_ext/time_spec.rb
79
+ - spec/spec_helper.rb
41
80
  homepage: http://www.esm.co.jp/
42
81
  licenses: []
43
82
  post_install_message:
@@ -58,8 +97,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
97
  version: '0'
59
98
  requirements: []
60
99
  rubyforge_project:
61
- rubygems_version: 1.6.2
100
+ rubygems_version: 1.8.15
62
101
  signing_key:
63
102
  specification_version: 3
64
103
  summary: GyomuRuby
65
- test_files: []
104
+ test_files:
105
+ - spec/core_ext/integer_spec.rb
106
+ - spec/core_ext/time_spec.rb
107
+ - spec/spec_helper.rb
108
+ has_rdoc: