ya_lorem_ja 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/lib/ya_lorem_ja.rb +6 -4
- data/lib/ya_lorem_ja/version.rb +1 -1
- data/lib/ya_lorem_ja/word_resource.rb +7 -5
- data/spec/ya_lorem_ja_spec.rb +10 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a602883c18997fb29d97e62173d0df408709875
|
4
|
+
data.tar.gz: 85c61c4e0210456bc26c8047b49cdc2c3fd3ba69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 574a262fb8db4319e2c3f7d9d2996f032d9575dcca6a0dc709c88d5fd17c16d339cc0b414d80940e0ee05a208ba2ea908445c74476c3bcd7f9d19019a7ca796d
|
7
|
+
data.tar.gz: bb22665b21cab5ab8b5ee71ecc18ac37af43a91316c02b12b1af703664c6b235b68c0fe1cfd3846eadf326ceaaca9fc1338b19c2f441a93fa39eb67632afa36e
|
data/README.md
CHANGED
@@ -52,8 +52,8 @@ Middleman の lorem のインターフェースを参考にしています。
|
|
52
52
|
- words(num_of_words)
|
53
53
|
- sentence
|
54
54
|
- sentences(num_of_sentces)
|
55
|
-
- paragraph
|
56
|
-
- paragraphs(num_of_paragraph)
|
55
|
+
- paragraph(options={})
|
56
|
+
- paragraphs(num_of_paragraph, options={})
|
57
57
|
- date(format)
|
58
58
|
- image(size, options={})
|
59
59
|
|
@@ -69,7 +69,8 @@ sentence(or sentence)が指定された場合は、1文あたり6〜15単語(コ
|
|
69
69
|
複数文(例: sentences(3))を指定した場合は、改行文字(デフォルト "\n", line_breakプロパティで変更可)で各文を結合します。
|
70
70
|
|
71
71
|
paragraph(or paragraphs)が指定された場合は、1段落あたり2〜5文(コンストラクタで変更可)の範囲でランダムに文数を決定し、文を選択します。
|
72
|
-
|
72
|
+
段落の前後に設定するセパレータを、オプション引数の開始セパレータ(:start_sep), 終了セパレータ(:end_sep) で指定できます。
|
73
|
+
(デフォルトは、開始セパレータは空文字で、終了セパレータは2つ分の改行文字になります。)
|
73
74
|
|
74
75
|
## 文章リソース
|
75
76
|
|
data/lib/ya_lorem_ja.rb
CHANGED
@@ -108,16 +108,18 @@ module YaLoremJa
|
|
108
108
|
##
|
109
109
|
# return a random paragraph from word resource
|
110
110
|
# @return [String] sentence
|
111
|
-
def paragraph
|
112
|
-
@resource.paragraph
|
111
|
+
def paragraph(opts={ })
|
112
|
+
@resource.paragraph(opts)
|
113
113
|
end
|
114
114
|
|
115
115
|
##
|
116
116
|
# return random paragraphs from word resource
|
117
117
|
# @param [Fixnum] total count of paragraph
|
118
118
|
# @return [String] paragraph
|
119
|
-
def paragraphs(total)
|
120
|
-
|
119
|
+
def paragraphs(total, opts={ })
|
120
|
+
default_opts = { start_sep: "", end_sep: line_break * 2 }
|
121
|
+
merged_opts = default_opts.merge(opts)
|
122
|
+
@resource.paragraphs(total, merged_opts)
|
121
123
|
end
|
122
124
|
|
123
125
|
|
data/lib/ya_lorem_ja/version.rb
CHANGED
@@ -121,21 +121,23 @@ module YaLoremJa
|
|
121
121
|
##
|
122
122
|
# return a random paragraph from word resource
|
123
123
|
# @return [String] sentence
|
124
|
-
def paragraph
|
125
|
-
paragraphs(1)
|
124
|
+
def paragraph(opts)
|
125
|
+
paragraphs(1, opts)
|
126
126
|
end
|
127
127
|
|
128
128
|
##
|
129
129
|
# return random paragraphs from word resource
|
130
130
|
# @param [Fixnum] total count of paragraph
|
131
131
|
# @return [String] paragraph
|
132
|
-
def paragraphs(total)
|
132
|
+
def paragraphs(total, opts)
|
133
133
|
list = []
|
134
134
|
total.times do
|
135
135
|
sentence_count = rand(sentence_count_range_in_a_paragraph)
|
136
|
-
|
136
|
+
start_sep = opts[:start_sep].to_s
|
137
|
+
end_sep = opts[:end_sep].to_s
|
138
|
+
list << start_sep + self.sentences(sentence_count) + end_sep
|
137
139
|
end
|
138
|
-
return list.join(
|
140
|
+
return list.join()
|
139
141
|
end
|
140
142
|
|
141
143
|
private
|
data/spec/ya_lorem_ja_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require 'spec_helper'
|
3
|
+
require 'pp'
|
3
4
|
|
4
5
|
describe YaLoremJa do
|
5
6
|
it 'should have a version number' do
|
@@ -59,6 +60,15 @@ describe YaLoremJa do
|
|
59
60
|
expect(a_para.split(/\n{1}/).count).to be >= lorem.sentence_count_range.min
|
60
61
|
end
|
61
62
|
|
63
|
+
it '<p></p>で囲まれた1段落を取得できること' do
|
64
|
+
lorem = YaLoremJa::Lorem.new
|
65
|
+
a_para = lorem.paragraph(start_sep: "<p>", end_sep: "</p>")
|
66
|
+
expect(a_para).not_to be_nil
|
67
|
+
puts a_para
|
68
|
+
expect(a_para).to match %r|<p>.+</p>|m
|
69
|
+
|
70
|
+
end
|
71
|
+
|
62
72
|
it '3段落を取得できること' do
|
63
73
|
lorem = YaLoremJa::Lorem.new
|
64
74
|
paras = lorem.paragraphs(3)
|
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
|
+
version: 0.0.4
|
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
|
+
date: 2015-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -101,3 +101,4 @@ test_files:
|
|
101
101
|
- spec/spec_helper.rb
|
102
102
|
- spec/ya_lorem_ja_chuumon_no_ooi_ryouriten_spec.rb
|
103
103
|
- spec/ya_lorem_ja_spec.rb
|
104
|
+
has_rdoc:
|