ya_lorem_ja 0.0.4 → 0.0.5

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: 2a602883c18997fb29d97e62173d0df408709875
4
- data.tar.gz: 85c61c4e0210456bc26c8047b49cdc2c3fd3ba69
3
+ metadata.gz: 8b2d6969ff39187dd9365fd433ab0d654fd44c07
4
+ data.tar.gz: f893ec3c80d15b1dae7dd9a0e742abfa6ba2a2af
5
5
  SHA512:
6
- metadata.gz: 574a262fb8db4319e2c3f7d9d2996f032d9575dcca6a0dc709c88d5fd17c16d339cc0b414d80940e0ee05a208ba2ea908445c74476c3bcd7f9d19019a7ca796d
7
- data.tar.gz: bb22665b21cab5ab8b5ee71ecc18ac37af43a91316c02b12b1af703664c6b235b68c0fe1cfd3846eadf326ceaaca9fc1338b19c2f441a93fa39eb67632afa36e
6
+ metadata.gz: a471c0c2d74937444105f7dfb3b2d7093e834871ac9298d723c86f1810eea4244110f5b984d7eaab4abd062be6d40ab3fc7b8224fd7e0c6972b8cdffa11862e5
7
+ data.tar.gz: af1d3fdf133ce08e314028061f4f1f4bcc3f7fd1b7cfa222b16996faa3c6ffd33f1e83d3d36b04815a7e719c70c9adee7e9483946d45d07b0d9c6cd649482c1f
@@ -4,7 +4,7 @@ require 'ya_lorem_ja/word_resource'
4
4
 
5
5
  ##
6
6
  # Yet Anothoer Japanese Lorem
7
- #
7
+ #
8
8
  module YaLoremJa
9
9
  ##
10
10
  # Japanese Lorem
@@ -15,13 +15,13 @@ module YaLoremJa
15
15
  DEFAULT_CHAR_COUNT_RANGE_IN_WORD = 2..6
16
16
  DEFAULT_WORD_COUNT_RANGE_IN_SENTENCE = 6..15
17
17
  DEFAULT_SENTENCE_COUNT_RANGE_IN_PARAGRAPH = 2..5
18
-
18
+
19
19
  ##
20
20
  # @param [Symbol] resource_name name of word resource
21
21
  # @param [Range] char_count_range range of character count in a word
22
22
  # @param [Range] word_count_range range of word count in sentence
23
23
  # @param [Range] sentence_count_range renage of sentence count in paragraph
24
- #
24
+ #
25
25
  def initialize(resource_name=DEFAULT_RESOURCE_NAME, char_count_range=DEFAULT_CHAR_COUNT_RANGE_IN_WORD, word_count_range=DEFAULT_WORD_COUNT_RANGE_IN_SENTENCE, sentence_count_range=DEFAULT_SENTENCE_COUNT_RANGE_IN_PARAGRAPH)
26
26
  @resource_name = resource_name
27
27
 
@@ -30,11 +30,15 @@ module YaLoremJa
30
30
  require File.join('ya_lorem_ja/resources', resource_name.to_s)
31
31
  rescue LoadError
32
32
  end
33
-
33
+
34
34
  # 文章辞書の読み込み
35
35
  @resource = ::YaLoremJa::WordResources.load(resource_name, char_count_range, word_count_range, sentence_count_range)
36
36
  end
37
37
 
38
+ def reload_resource(resource_name=DEFAULT_RESOURCE_NAME, char_count_range=DEFAULT_CHAR_COUNT_RANGE_IN_WORD, word_count_range=DEFAULT_WORD_COUNT_RANGE_IN_SENTENCE, sentence_count_range=DEFAULT_SENTENCE_COUNT_RANGE_IN_PARAGRAPH)
39
+ initialize(resource_name, char_count_range, word_count_range, sentence_count_range)
40
+ end
41
+
38
42
  ##
39
43
  # @return [Range] range of character count in a word
40
44
  def char_count_range
@@ -46,7 +50,7 @@ module YaLoremJa
46
50
  def word_count_range
47
51
  return @resource.word_count_range_in_a_sentence
48
52
  end
49
-
53
+
50
54
  ##
51
55
  # @return [Range] range of sentence count in a paragraph
52
56
  def sentence_count_range
@@ -91,7 +95,7 @@ module YaLoremJa
91
95
 
92
96
  ##
93
97
  # return a random sentence from word resource
94
- # @return [String] sentence
98
+ # @return [String] sentence
95
99
  def sentence
96
100
  @resource.sentence
97
101
  end
@@ -107,7 +111,7 @@ module YaLoremJa
107
111
 
108
112
  ##
109
113
  # return a random paragraph from word resource
110
- # @return [String] sentence
114
+ # @return [String] sentence
111
115
  def paragraph(opts={ })
112
116
  @resource.paragraph(opts)
113
117
  end
@@ -115,7 +119,7 @@ module YaLoremJa
115
119
  ##
116
120
  # return random paragraphs from word resource
117
121
  # @param [Fixnum] total count of paragraph
118
- # @return [String] paragraph
122
+ # @return [String] paragraph
119
123
  def paragraphs(total, opts={ })
120
124
  default_opts = { start_sep: "", end_sep: line_break * 2 }
121
125
  merged_opts = default_opts.merge(opts)
@@ -130,7 +134,7 @@ module YaLoremJa
130
134
  Time.local(y, m, d).strftime(fmt)
131
135
  end
132
136
 
133
-
137
+
134
138
  # Get a placeholder image, using placehold.it by default
135
139
  # @param [String] size
136
140
  # @param [Hash] options
@@ -154,6 +158,6 @@ module YaLoremJa
154
158
 
155
159
  src
156
160
  end
157
-
161
+
158
162
  end
159
163
  end
@@ -1,5 +1,5 @@
1
1
  module YaLoremJa
2
2
  ##
3
3
  # version
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.5"
5
5
  end
@@ -1,10 +1,16 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module YaLoremJa
3
-
3
+
4
4
  ##
5
5
  # manage word resources
6
6
  module WordResources
7
+ @default_resource_name = :kazehakase
7
8
  class << self
9
+
10
+ def default_resource_name=(resource_name)
11
+ @default_resource_name = resource_name
12
+ end
13
+
8
14
  ##
9
15
  # retrun repository of word resource
10
16
  def resource
@@ -36,7 +42,7 @@ module YaLoremJa
36
42
  end
37
43
  return kls.new(char_count_range, word_count_range, sentence_count_range)
38
44
  end
39
-
45
+
40
46
  end
41
47
  end
42
48
 
@@ -58,7 +64,7 @@ module YaLoremJa
58
64
  def initialize(char_count_range, word_count_range, sentence_count_range)
59
65
  # 単語の文字数範囲の設定
60
66
  @char_count_range_in_a_word = char_count_range
61
- # 文の単語数範囲の設定
67
+ # 文の単語数範囲の設定
62
68
  @word_count_range_in_a_sentence = word_count_range
63
69
  # 段落の文数範囲の設定
64
70
  @sentence_count_range_in_a_paragraph = sentence_count_range
@@ -72,7 +78,7 @@ module YaLoremJa
72
78
 
73
79
  ##
74
80
  # return a random word from word resource
75
- # @return [String] word
81
+ # @return [String] word
76
82
  def word
77
83
  words(1)
78
84
  end
@@ -81,7 +87,7 @@ module YaLoremJa
81
87
  # return rondom words from word resource
82
88
  #
83
89
  # @param [Fixnum] total count of word
84
- # @return [String] words
90
+ # @return [String] words
85
91
  def words(num_of_word)
86
92
  target_len = num_of_word.times.inject(0){ |sum| sum + rand(@char_count_range_in_a_word) }
87
93
  sentence_key = bsearch(sentence_map_keys, target_len)
@@ -89,12 +95,12 @@ module YaLoremJa
89
95
  sentence_key = sentence_map.keys.min
90
96
  end
91
97
  wk_word = sentence_map[sentence_key].sample
92
- return wk_word.sub(/[#{ sentence_end_chars.join() }]$/, "")
98
+ return wk_word.sub(/[#{ sentence_end_chars.join() }]$/, "")
93
99
  end
94
100
 
95
101
  ##
96
102
  # return a random sentence from word resource
97
- # @return [String] sentence
103
+ # @return [String] sentence
98
104
  def sentence
99
105
  sentences(1)
100
106
  end
@@ -103,7 +109,7 @@ module YaLoremJa
103
109
  # return rondom sentences from word resource
104
110
  #
105
111
  # @param [Fixnum] total count of sentence
106
- # @return [String] words
112
+ # @return [String] words
107
113
  def sentences(total)
108
114
  list = []
109
115
  total.times do
@@ -120,7 +126,7 @@ module YaLoremJa
120
126
 
121
127
  ##
122
128
  # return a random paragraph from word resource
123
- # @return [String] sentence
129
+ # @return [String] sentence
124
130
  def paragraph(opts)
125
131
  paragraphs(1, opts)
126
132
  end
@@ -128,7 +134,7 @@ module YaLoremJa
128
134
  ##
129
135
  # return random paragraphs from word resource
130
136
  # @param [Fixnum] total count of paragraph
131
- # @return [String] paragraph
137
+ # @return [String] paragraph
132
138
  def paragraphs(total, opts)
133
139
  list = []
134
140
  total.times do
@@ -159,5 +165,5 @@ module YaLoremJa
159
165
  end
160
166
  end
161
167
 
162
-
168
+
163
169
  end
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe YaLoremJa do
5
+
6
+ it 'インスタンスのリソースを切り替え可能なこと' do
7
+ lorem = YaLoremJa::Lorem.new(:chuumon_no_ooi_ryouriten)
8
+ expect(lorem).not_to be_nil
9
+ expect(lorem.resource_name).to be == :chuumon_no_ooi_ryouriten
10
+ lorem.reload_resource(:kazehakase)
11
+ expect(lorem.resource_name).to be == :kazehakase
12
+ expect(lorem).not_to be_nil
13
+ end
14
+
15
+
16
+ end
@@ -66,8 +66,8 @@ describe YaLoremJa do
66
66
  expect(a_para).not_to be_nil
67
67
  puts a_para
68
68
  expect(a_para).to match %r|<p>.+</p>|m
69
-
70
- end
69
+
70
+ end
71
71
 
72
72
  it '3段落を取得できること' do
73
73
  lorem = YaLoremJa::Lorem.new
@@ -79,13 +79,13 @@ describe YaLoremJa do
79
79
  expect(a_para.split(/\n{1}/).count).to be >= lorem.sentence_count_range.min
80
80
  end
81
81
  end
82
-
82
+
83
83
  it '改行文字を変更時、文の改行文字も変更されること' do
84
84
  lorem = YaLoremJa::Lorem.new
85
85
  lorem.line_break = "\r\n"
86
86
  sentences = lorem.sentences(3)
87
87
  p sentences
88
- expect(sentences.split("\r\n").count).to be == 3
88
+ expect(sentences.split("\r\n").count).to be == 3
89
89
  end
90
90
 
91
91
  it '改行文字を変更時、段落の改行文字も変更されること' do
@@ -110,5 +110,5 @@ describe YaLoremJa do
110
110
  lorem = YaLoremJa::Lorem.new
111
111
  expect(lorem.image('20x20')).to match %r!^http://placehold.it/20x20$!
112
112
  end
113
-
113
+
114
114
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ya_lorem_ja
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - kenji tanaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
11
+ date: 2015-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,7 @@ files:
71
71
  - lib/ya_lorem_ja/word_resource.rb
72
72
  - spec/spec_helper.rb
73
73
  - spec/ya_lorem_ja_chuumon_no_ooi_ryouriten_spec.rb
74
+ - spec/ya_lorem_ja_reload_resource_spec.rb
74
75
  - spec/ya_lorem_ja_spec.rb
75
76
  - ya_lorem_ja.gemspec
76
77
  homepage: https://github.com/tanalab2/ya_lorem_ja
@@ -100,5 +101,6 @@ summary: Yet Another Japanese Lorem Ipsum generator
100
101
  test_files:
101
102
  - spec/spec_helper.rb
102
103
  - spec/ya_lorem_ja_chuumon_no_ooi_ryouriten_spec.rb
104
+ - spec/ya_lorem_ja_reload_resource_spec.rb
103
105
  - spec/ya_lorem_ja_spec.rb
104
106
  has_rdoc: