fOOrth 0.6.7 → 0.6.8
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/CODE_OF_CONDUCT.md +49 -0
- data/fOOrth.gemspec +1 -1
- data/integration/stdio_lib_tests.rb +62 -0
- data/integration/thread_lib_tests.rb +16 -5
- data/lib/fOOrth.rb +0 -2
- data/lib/fOOrth/library/formatting/array.rb +81 -0
- data/lib/fOOrth/library/formatting/bullets.rb +16 -90
- data/lib/fOOrth/library/formatting/columns.rb +20 -44
- data/lib/fOOrth/library/formatting/hash.rb +29 -0
- data/lib/fOOrth/library/formatting/nil.rb +13 -0
- data/lib/fOOrth/library/formatting/object.rb +13 -0
- data/lib/fOOrth/library/formatting/string.rb +46 -0
- data/lib/fOOrth/library/stdio_library.rb +11 -8
- data/lib/fOOrth/version.rb +1 -1
- data/sire.rb +0 -1
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b26e1b244da5adaa8fc5c44878adf0a23b1f066
|
4
|
+
data.tar.gz: 0d6f3fcc299062f5a1729a0fb11612e7c6744825
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee1b60bcd99441e124425f06ed89d3a1dbdfd30905b1cc6898833f47323c52a6a6d1163730604c758a017c7a0174275a53e2d73e20d2ec0d6b8157bf2fb2a95f
|
7
|
+
data.tar.gz: 96115428006a4d71003c6060239814debcf44c57aae4627287ceb0ec5377a68f85da6d8a8dd38b886aea912f965b2124b769c41993134dff18eaf81e3a967aec
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at peter.c.camilleri@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/fOOrth.gemspec
CHANGED
@@ -36,5 +36,5 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_runtime_dependency 'full_clone'
|
37
37
|
spec.add_runtime_dependency 'safe_clone'
|
38
38
|
spec.add_runtime_dependency 'in_array'
|
39
|
-
spec.add_runtime_dependency 'mini_readline', ">= 0.
|
39
|
+
spec.add_runtime_dependency 'mini_readline', ">= 0.7.0"
|
40
40
|
end
|
@@ -49,4 +49,66 @@ class StdioLibraryTester < Minitest::Test
|
|
49
49
|
foorth_raises('1+1i .emit')
|
50
50
|
end
|
51
51
|
|
52
|
+
#Looks like some unit testing has crept into integration testing. OK.
|
53
|
+
def test_some_formatting
|
54
|
+
assert_equal("1 4\n2 5\n3 ", [1,2,3,4,5].format_foorth_columns(false, 5))
|
55
|
+
assert_equal(["1 4", "2 5", "3 "], [1,2,3,4,5].format_description(5))
|
56
|
+
|
57
|
+
assert_equal(["1 2", "3 4", "5"], "1 2 3 4 5".format_description(5))
|
58
|
+
|
59
|
+
assert_equal([], [].format_description(5))
|
60
|
+
assert_equal([], nil.format_description(5))
|
61
|
+
|
62
|
+
result =
|
63
|
+
"1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81 85 89 93 97 \n" +
|
64
|
+
"2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 \n" +
|
65
|
+
"3 7 11 15 19 23 27 31 35 39 43 47 51 55 59 63 67 71 75 79 83 87 91 95 99 \n" +
|
66
|
+
"4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100"
|
67
|
+
|
68
|
+
assert_equal(result, (1..100).to_a.format_foorth_columns(false, 80) )
|
69
|
+
|
70
|
+
data =
|
71
|
+
[["key_largo", "/long_folder_name_one/long_folder_name_two/long_folder_name_three/fine_descriptive_name"],
|
72
|
+
["key_west", "Semper ubi sub ubi. Semper ubi sub ubi. Semper ubi sub ubi. Semper ubi sub ubi. "],
|
73
|
+
["counting", Array.new(100) {|i| i} ],
|
74
|
+
["pie", Math::PI]
|
75
|
+
]
|
76
|
+
|
77
|
+
result =
|
78
|
+
"key_largo /long_folder_name_one/long_folder_name_two/long_folder_name_three/fin\n" +
|
79
|
+
" e_descriptive_name\n" +
|
80
|
+
"key_west Semper ubi sub ubi. Semper ubi sub ubi. Semper ubi sub ubi. Semper\n" +
|
81
|
+
" ubi sub ubi.\n" +
|
82
|
+
"counting 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95\n" +
|
83
|
+
" 1 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 86 91 96\n" +
|
84
|
+
" 2 7 12 17 22 27 32 37 42 47 52 57 62 67 72 77 82 87 92 97\n" +
|
85
|
+
" 3 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 83 88 93 98\n" +
|
86
|
+
" 4 9 14 19 24 29 34 39 44 49 54 59 64 69 74 79 84 89 94 99\n" +
|
87
|
+
"pie 3.141592653589793"
|
88
|
+
|
89
|
+
assert_equal(result, data.foorth_format_bullets(80))
|
90
|
+
|
91
|
+
assert_equal("", [].foorth_format_bullets(80))
|
92
|
+
|
93
|
+
|
94
|
+
data =
|
95
|
+
{"key_largo" => "/long_folder_name_one/long_folder_name_two/long_folder_name_three/fine_descriptive_name",
|
96
|
+
"key_west" => "Semper ubi sub ubi. Semper ubi sub ubi. Semper ubi sub ubi. Semper ubi sub ubi. ",
|
97
|
+
"counting" => Array.new(100) {|i| i},
|
98
|
+
"pie" => Math::PI
|
99
|
+
}
|
100
|
+
|
101
|
+
assert_equal(result, data.foorth_format_bullets(80))
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_formatting_some_more
|
106
|
+
foorth_run('5 $chars_per_line !')
|
107
|
+
foorth_equal('[ 1 2 3 4 5 ] .format_columns', ["1 4\n2 5\n3 "])
|
108
|
+
|
109
|
+
foorth_run('80 $chars_per_line !')
|
110
|
+
foorth_equal('[ [ 1 "apple" ] [ 2 "cherry" ] [ 3 "prune" ] ] .format_bullets',
|
111
|
+
["1 apple\n2 cherry\n3 prune"])
|
112
|
+
end
|
113
|
+
|
52
114
|
end
|
@@ -71,13 +71,24 @@ class ThreadLibraryTester < Minitest::Test
|
|
71
71
|
foorth_run('$tmtx .lock $tmtx .unlock ')
|
72
72
|
foorth_equal('$tmtx .do{{ 3 4 + }}', [7])
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
code = ': test_mutex_one ' +
|
75
|
+
'{{ $tmtx .do{{ 0 10 do $tmtx_str "@" << loop }} }} .start drop ' +
|
76
|
+
'begin $tmtx .do{{ $tmtx_str }} "" = while again $tmtx_str ;'
|
77
77
|
|
78
78
|
foorth_run('""* val$: $tmtx_str')
|
79
|
-
|
80
|
-
|
79
|
+
foorth_run(code)
|
80
|
+
|
81
|
+
10.times do
|
82
|
+
foorth_equal('""* val$: $tmtx_str test_mutex_one', ["@"*10])
|
83
|
+
end
|
84
|
+
|
85
|
+
code = '{{ Mutex .do{{ 0 10 do $tmtx_str "@" << loop }} }} .start drop ' +
|
86
|
+
'begin Mutex .do{{ $tmtx_str }} "" = while again $tmtx_str'
|
87
|
+
|
88
|
+
10.times do
|
89
|
+
foorth_run('""* val$: $tmtx_str')
|
90
|
+
foorth_equal(code, ["@"*10])
|
91
|
+
end
|
81
92
|
end
|
82
93
|
|
83
94
|
end
|
data/lib/fOOrth.rb
CHANGED
@@ -0,0 +1,81 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* library/formatting/array.rb - Array support for displaying data formatted neatly.
|
4
|
+
class Array
|
5
|
+
|
6
|
+
# Columns ========================================================
|
7
|
+
|
8
|
+
#Print out the array with efficient columns.
|
9
|
+
def puts_foorth_columns(page_length, page_width)
|
10
|
+
format_foorth_pages(page_length, page_width).each do |page|
|
11
|
+
puts page, ""
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
#Convert the array to strings with efficient columns.
|
16
|
+
#<br>Returns
|
17
|
+
#* A string.
|
18
|
+
def format_foorth_columns(page_length, page_width)
|
19
|
+
format_foorth_pages(page_length, page_width)
|
20
|
+
.map {|page| page << ""}
|
21
|
+
.flatten[0...-1]
|
22
|
+
.join("\n")
|
23
|
+
.freeze
|
24
|
+
end
|
25
|
+
|
26
|
+
#Get the widest element of an array.
|
27
|
+
#<br>Returns
|
28
|
+
#* The width of the widest string in the array.
|
29
|
+
def foorth_column_width
|
30
|
+
(self.max_by {|item| item.length}).length
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
#Convert the array to strings with efficient columns.
|
36
|
+
#<br>Returns
|
37
|
+
#* An array of pages (arrays of strings)
|
38
|
+
def format_foorth_pages(page_length, page_width)
|
39
|
+
index, pages, limit = 0, [], self.length
|
40
|
+
builder = XfOOrth::ColumnizedPage.new(page_length, page_width)
|
41
|
+
|
42
|
+
while index < limit
|
43
|
+
index += 1 - (left_over = builder.add(self[index]))
|
44
|
+
pages << builder.render if (left_over > 0) || (index == limit)
|
45
|
+
end
|
46
|
+
|
47
|
+
pages
|
48
|
+
end
|
49
|
+
|
50
|
+
# Bullets ========================================================
|
51
|
+
|
52
|
+
public
|
53
|
+
|
54
|
+
#Print out the array as bullet points.
|
55
|
+
def puts_foorth_bullets
|
56
|
+
puts foorth_format_bullets
|
57
|
+
end
|
58
|
+
|
59
|
+
#Convert the array to strings with bullet points.
|
60
|
+
#<br>Returns
|
61
|
+
#* A string
|
62
|
+
def foorth_format_bullets(page_width)
|
63
|
+
return "" if empty?
|
64
|
+
|
65
|
+
builder = XfOOrth::BulletPoints.new(page_width)
|
66
|
+
|
67
|
+
self.each do |pair|
|
68
|
+
builder.add(*pair)
|
69
|
+
end
|
70
|
+
|
71
|
+
builder.render.join("\n").freeze
|
72
|
+
end
|
73
|
+
|
74
|
+
#Convert the array to a bullet point description.
|
75
|
+
#<br>Returns
|
76
|
+
#* An array of strings.
|
77
|
+
def format_description(page_width)
|
78
|
+
format_foorth_pages(false, page_width)[0] || []
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -5,32 +5,22 @@ module XfOOrth
|
|
5
5
|
|
6
6
|
#A class to display data in bullet points.
|
7
7
|
class BulletPoints
|
8
|
+
|
8
9
|
#Prepare a blank slate.
|
9
10
|
def initialize(page_width)
|
10
|
-
@page_width
|
11
|
+
@page_width = page_width
|
12
|
+
@bullet_data = []
|
11
13
|
end
|
12
14
|
|
13
|
-
#Add
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def add(raw_bullet = "*", *raw_item)
|
19
|
-
|
20
|
-
if raw_item.empty?
|
21
|
-
bullet = ["*"]
|
22
|
-
items = raw_bullet.in_array
|
23
|
-
else
|
24
|
-
bullet = [raw_bullet]
|
25
|
-
items = raw_item.in_array
|
26
|
-
end
|
27
|
-
|
28
|
-
items.each_index do |index|
|
29
|
-
@bullet_data << [(bullet[index] || "").to_s, items[index].to_s]
|
15
|
+
#Add items to these bullet points.
|
16
|
+
def add(bullet, *items)
|
17
|
+
items.each do |item|
|
18
|
+
@bullet_data << [bullet.to_s, item]
|
19
|
+
bullet = ""
|
30
20
|
end
|
31
21
|
end
|
32
22
|
|
33
|
-
#Render the
|
23
|
+
#Render the bullet points as an array of strings.
|
34
24
|
def render
|
35
25
|
@key_length, results = get_key_length, []
|
36
26
|
|
@@ -44,88 +34,24 @@ module XfOOrth
|
|
44
34
|
|
45
35
|
private
|
46
36
|
|
47
|
-
#
|
37
|
+
#Allowing for a trailing space, how large is the largest bullet?
|
48
38
|
def get_key_length
|
49
|
-
(@bullet_data.max_by {|line| line[0].length})[0].length
|
39
|
+
(@bullet_data.max_by {|line| line[0].length})[0].length + 1
|
50
40
|
end
|
51
41
|
|
52
42
|
#Render one bullet point.
|
53
|
-
#<br>Endemic Code Smells
|
54
|
-
#* :reek:DuplicateMethodCall :reek:TooManyStatements
|
55
43
|
def render_bullet(key, item)
|
56
|
-
result
|
57
|
-
input = item.split(' ').each
|
58
|
-
temp = key.ljust(len = @key_length)
|
59
|
-
|
60
|
-
loop do
|
61
|
-
word = ' ' + input.next
|
44
|
+
result = []
|
62
45
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
len = temp.length
|
67
|
-
end
|
68
|
-
|
69
|
-
if ((len += word.length) >= @page_width) && !pass_one
|
70
|
-
result << temp
|
71
|
-
temp = blank_key + word
|
72
|
-
len = temp.length
|
73
|
-
else
|
74
|
-
temp << word
|
75
|
-
pass_one = false
|
76
|
-
end
|
46
|
+
item.format_description(@page_width - @key_length - 1).each do |desc_line|
|
47
|
+
result << key.ljust(@key_length) + desc_line
|
48
|
+
key = ""
|
77
49
|
end
|
78
50
|
|
79
|
-
result
|
80
|
-
end
|
81
|
-
|
82
|
-
#Generate a blank bullet key
|
83
|
-
def blank_key
|
84
|
-
' ' * @key_length
|
51
|
+
result
|
85
52
|
end
|
86
53
|
|
87
54
|
end
|
88
55
|
|
89
56
|
end
|
90
57
|
|
91
|
-
#Bullet point support in the Array class.
|
92
|
-
class Array
|
93
|
-
#Print out the array as bullet points.
|
94
|
-
def puts_foorth_bullets(page_width)
|
95
|
-
puts foorth_bulletize(page_width)
|
96
|
-
end
|
97
|
-
|
98
|
-
#Convert the array to strings with bullet points.
|
99
|
-
#<br>
|
100
|
-
#* An array of arrays of strings
|
101
|
-
def foorth_bulletize(page_width)
|
102
|
-
builder = XfOOrth::BulletPoints.new(page_width)
|
103
|
-
|
104
|
-
self.each do |pair|
|
105
|
-
builder.add(*pair)
|
106
|
-
end
|
107
|
-
|
108
|
-
builder.render
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
#Bullet point support in the Hash class.
|
113
|
-
class Hash
|
114
|
-
#Print out the hash as bullet points.
|
115
|
-
def puts_foorth_bullets(page_width)
|
116
|
-
puts foorth_bulletize(page_width)
|
117
|
-
end
|
118
|
-
|
119
|
-
#Convert the hash to strings with bullet points.
|
120
|
-
#<br>
|
121
|
-
#* An array of arrays of strings
|
122
|
-
def foorth_bulletize(page_width)
|
123
|
-
builder = XfOOrth::BulletPoints.new(page_width)
|
124
|
-
|
125
|
-
self.each do |key, value|
|
126
|
-
builder.add(key, *value.in_array)
|
127
|
-
end
|
128
|
-
|
129
|
-
builder.render
|
130
|
-
end
|
131
|
-
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
#* library/formatting/
|
3
|
+
#* library/formatting/bullets.rb - Print out data in neat columns.
|
4
4
|
module XfOOrth
|
5
5
|
|
6
6
|
#A class to display data in columns.
|
@@ -18,8 +18,8 @@ module XfOOrth
|
|
18
18
|
item = raw_item.to_s
|
19
19
|
fail "Item too large to fit." unless item.length < @page_width
|
20
20
|
|
21
|
-
if (
|
22
|
-
@page_data[
|
21
|
+
if (column = find_next_column)
|
22
|
+
@page_data[column] << item
|
23
23
|
else
|
24
24
|
@page_data << [item]
|
25
25
|
end
|
@@ -28,24 +28,29 @@ module XfOOrth
|
|
28
28
|
end
|
29
29
|
|
30
30
|
#Render the page as an array of strings.
|
31
|
-
#<br>Endemic Code Smells
|
32
|
-
#* :reek:NestedIterators :reek:TooManyStatements
|
33
31
|
def render
|
34
|
-
results = []
|
35
|
-
widths = @page_data.map {|column| column.foorth_column_width}
|
32
|
+
results, column_widths = [], get_column_widths
|
36
33
|
|
37
|
-
|
38
|
-
results << @page_data.each_with_index.map do |column, index|
|
39
|
-
column[column_index].to_s.ljust(widths[index])
|
40
|
-
end.join(" ").freeze
|
41
|
-
end
|
34
|
+
rows.times { |row_index| results << render_row(row_index, column_widths)}
|
42
35
|
|
43
|
-
@page_data
|
36
|
+
@page_data.clear
|
44
37
|
results
|
45
38
|
end
|
46
39
|
|
47
40
|
private
|
48
41
|
|
42
|
+
#Get the widths of all columns
|
43
|
+
def get_column_widths
|
44
|
+
@page_data.map {|column| column.foorth_column_width}
|
45
|
+
end
|
46
|
+
|
47
|
+
#Render a single row of data.
|
48
|
+
def render_row(row_index, widths)
|
49
|
+
@page_data.each_with_index.map do |column, index|
|
50
|
+
column[row_index].to_s.ljust(widths[index])
|
51
|
+
end.join(" ")
|
52
|
+
end
|
53
|
+
|
49
54
|
#Make sure the page fits within its boundaries.
|
50
55
|
#<br>Returns
|
51
56
|
#* The number if items that did not fit in the page.
|
@@ -76,6 +81,8 @@ module XfOOrth
|
|
76
81
|
if empty?
|
77
82
|
0
|
78
83
|
else
|
84
|
+
#The starting point, @page_data.length-1, represents the spaces needed
|
85
|
+
#between the columns. So N columns means N-1 spaces.
|
79
86
|
@page_data.inject(@page_data.length-1) do |sum, column|
|
80
87
|
sum + column.foorth_column_width
|
81
88
|
end
|
@@ -113,34 +120,3 @@ module XfOOrth
|
|
113
120
|
|
114
121
|
end
|
115
122
|
|
116
|
-
#Support for displaying an array in neat columns.
|
117
|
-
class Array
|
118
|
-
#Print out the array with efficient columns.
|
119
|
-
def puts_foorth_columnized(page_length, page_width)
|
120
|
-
foorth_columnize(page_length, page_width).each do |page|
|
121
|
-
puts page
|
122
|
-
puts
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
#Convert the array to strings with efficient columns.
|
127
|
-
#<br>
|
128
|
-
#* An array of arrays of strings
|
129
|
-
def foorth_columnize(page_length, page_width)
|
130
|
-
index, pages, limit = 0, [], self.length
|
131
|
-
builder = XfOOrth::ColumnizedPage.new(page_length, page_width)
|
132
|
-
|
133
|
-
while index < limit
|
134
|
-
index += 1 - (left_over = builder.add(self[index]))
|
135
|
-
pages << builder.render if (left_over > 0) || (index == limit)
|
136
|
-
end
|
137
|
-
|
138
|
-
pages
|
139
|
-
end
|
140
|
-
|
141
|
-
#Get the widest element of an array.
|
142
|
-
def foorth_column_width
|
143
|
-
(self.max_by {|item| item.length}).length
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* library/formatting/hash.rb - Hash support for displaying data formatted neatly.
|
4
|
+
class Hash
|
5
|
+
|
6
|
+
# Bullets ========================================================
|
7
|
+
|
8
|
+
#Print out the array as bullet points.
|
9
|
+
def puts_foorth_bullets
|
10
|
+
puts foorth_format_bullets
|
11
|
+
end
|
12
|
+
|
13
|
+
#Convert the array to strings with bullet points.
|
14
|
+
#<br>Returns
|
15
|
+
#* A string.
|
16
|
+
def foorth_format_bullets(page_width)
|
17
|
+
return "" if empty?
|
18
|
+
|
19
|
+
builder = XfOOrth::BulletPoints.new(page_width)
|
20
|
+
|
21
|
+
self.each do |pair|
|
22
|
+
builder.add(*pair)
|
23
|
+
end
|
24
|
+
|
25
|
+
builder.render.join("\n").freeze
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* library/formatting/object.rb - Support for displaying data formatted neatly.
|
4
|
+
class Object
|
5
|
+
|
6
|
+
#Create a bullet point description from this object.
|
7
|
+
def format_description(max_width)
|
8
|
+
self.to_s.format_description(max_width)
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* library/formatting/string.rb - Support for displaying data formatted neatly.
|
4
|
+
class String
|
5
|
+
|
6
|
+
#Create a bullet point description from this string.
|
7
|
+
def format_description(max_width)
|
8
|
+
do_format_description(split(' ').each, max_width)
|
9
|
+
end
|
10
|
+
|
11
|
+
#Do the formatting legwork.
|
12
|
+
def do_format_description(input, max_width)
|
13
|
+
result, build = [], ""
|
14
|
+
|
15
|
+
loop do
|
16
|
+
build = build.split_if_over(input.next, max_width, result)
|
17
|
+
.split_if_huge(max_width, result)
|
18
|
+
end
|
19
|
+
|
20
|
+
result << build
|
21
|
+
end
|
22
|
+
|
23
|
+
#Split if adding a word goes over a little.
|
24
|
+
def split_if_over(word, max_width, buffer)
|
25
|
+
word.prepend(" ") unless self.empty?
|
26
|
+
word_len = word.length
|
27
|
+
|
28
|
+
if (length + word_len) >= max_width && word_len < max_width
|
29
|
+
buffer << self
|
30
|
+
word.lstrip
|
31
|
+
else
|
32
|
+
self + word
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
#Split up a overlong blob of text.
|
38
|
+
def split_if_huge(max_width, buffer)
|
39
|
+
while length >= max_width
|
40
|
+
buffer << slice!(0, max_width)
|
41
|
+
end
|
42
|
+
|
43
|
+
self
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
@@ -1,6 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
#Load up some pretty printing support.
|
4
|
+
require_relative 'formatting/nil'
|
5
|
+
require_relative 'formatting/object'
|
6
|
+
require_relative 'formatting/string'
|
7
|
+
require_relative 'formatting/array'
|
8
|
+
require_relative 'formatting/hash'
|
4
9
|
require_relative 'formatting/columns'
|
5
10
|
require_relative 'formatting/bullets'
|
6
11
|
|
@@ -65,7 +70,7 @@ module XfOOrth
|
|
65
70
|
|
66
71
|
symbol = :chars_per_line
|
67
72
|
$chars_per_line = [80]
|
68
|
-
SymbolMap.add_entry('$chars_per_line',
|
73
|
+
SymbolMap.add_entry('$chars_per_line', symbol)
|
69
74
|
$FOORTH_GLOBALS[symbol] = GlobalVarSpec.new('$chars_per_line', symbol, [])
|
70
75
|
|
71
76
|
#Show the page length.
|
@@ -86,24 +91,22 @@ module XfOOrth
|
|
86
91
|
|
87
92
|
# [ l 2 3 ... n ] .pp []; pretty print the array!
|
88
93
|
Array.create_shared_method('.pp', TosSpec, [], &lambda {|vm|
|
89
|
-
|
94
|
+
puts_foorth_columns($lines_per_page[0], $chars_per_line[0])
|
90
95
|
})
|
91
96
|
|
92
97
|
# [ l 2 3 ... n ] .format_columns []; format to strings with columns.
|
93
98
|
Array.create_shared_method('.format_columns', TosSpec, [], &lambda {|vm|
|
94
|
-
vm.push(
|
95
|
-
.map {|page| page << ""}
|
96
|
-
.flatten[0...-1])
|
99
|
+
vm.push(format_foorth_columns($lines_per_page[0], $chars_per_line[0]))
|
97
100
|
})
|
98
101
|
|
99
102
|
# [ l 2 3 ... n ] .print_columns []; pretty print columns.
|
100
103
|
Array.create_shared_method('.print_columns', TosSpec, [], &lambda {|vm|
|
101
|
-
|
104
|
+
puts_foorth_columns($lines_per_page[0], $chars_per_line[0])
|
102
105
|
})
|
103
106
|
|
104
107
|
#[["1" "stuff"] ["two" stuff] .format_bullets; format to strings with bullets.
|
105
108
|
Array.create_shared_method('.format_bullets', TosSpec, [], &lambda {|vm|
|
106
|
-
vm.push(
|
109
|
+
vm.push(foorth_format_bullets($chars_per_line[0]))
|
107
110
|
})
|
108
111
|
|
109
112
|
#[["1" "stuff"] ["two" stuff] .print_bullets; pretty print bullet points.
|
@@ -113,7 +116,7 @@ module XfOOrth
|
|
113
116
|
|
114
117
|
#{ "1" "stuff" -> "two" "stuff" -> } .format_bullets; format to strings with bullets.
|
115
118
|
Hash.create_shared_method('.format_bullets', TosSpec, [], &lambda {|vm|
|
116
|
-
vm.push(
|
119
|
+
vm.push(foorth_format_bullets($chars_per_line[0]))
|
117
120
|
})
|
118
121
|
|
119
122
|
#{ "1" "stuff" -> "two" "stuff" -> } .print_bullets; pretty print bullet points.
|
data/lib/fOOrth/version.rb
CHANGED
data/sire.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fOOrth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Camilleri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -170,14 +170,14 @@ dependencies:
|
|
170
170
|
requirements:
|
171
171
|
- - ">="
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: 0.
|
173
|
+
version: 0.7.0
|
174
174
|
type: :runtime
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: 0.
|
180
|
+
version: 0.7.0
|
181
181
|
description: An Object Oriented FORTHesque language gem.
|
182
182
|
email: peter.c.camilleri@gmail.com
|
183
183
|
executables:
|
@@ -187,6 +187,7 @@ extra_rdoc_files: []
|
|
187
187
|
files:
|
188
188
|
- ".gitignore"
|
189
189
|
- ".rdoc_options"
|
190
|
+
- CODE_OF_CONDUCT.md
|
190
191
|
- Gemfile
|
191
192
|
- README.md
|
192
193
|
- bin/fOOrth
|
@@ -282,8 +283,13 @@ files:
|
|
282
283
|
- lib/fOOrth/library/duration/make.rb
|
283
284
|
- lib/fOOrth/library/duration_library.rb
|
284
285
|
- lib/fOOrth/library/fiber_library.rb
|
286
|
+
- lib/fOOrth/library/formatting/array.rb
|
285
287
|
- lib/fOOrth/library/formatting/bullets.rb
|
286
288
|
- lib/fOOrth/library/formatting/columns.rb
|
289
|
+
- lib/fOOrth/library/formatting/hash.rb
|
290
|
+
- lib/fOOrth/library/formatting/nil.rb
|
291
|
+
- lib/fOOrth/library/formatting/object.rb
|
292
|
+
- lib/fOOrth/library/formatting/string.rb
|
287
293
|
- lib/fOOrth/library/hash_library.rb
|
288
294
|
- lib/fOOrth/library/in_stream_library.rb
|
289
295
|
- lib/fOOrth/library/integer_library.rb
|
@@ -371,7 +377,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
371
377
|
version: '0'
|
372
378
|
requirements: []
|
373
379
|
rubyforge_project:
|
374
|
-
rubygems_version: 2.2.
|
380
|
+
rubygems_version: 2.2.3
|
375
381
|
signing_key:
|
376
382
|
specification_version: 4
|
377
383
|
summary: FNF == fOOrth is Not FORTH.
|