ludy 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +11 -1
- data/README +5 -6
- data/lib/ludy.rb +1 -1
- data/lib/ludy/array/body.rb +2 -2
- data/lib/ludy/array/combine.rb +8 -7
- data/lib/ludy/array/combos.rb +6 -5
- data/lib/ludy/array/map_with_index.rb +1 -0
- data/lib/ludy/array/rotate.rb +1 -1
- data/lib/ludy/array/tail.rb +2 -1
- data/lib/ludy/dices.rb +2 -0
- data/lib/ludy/kernel/deep_copy.rb +2 -0
- data/lib/ludy/kernel/maybe.rb +3 -0
- data/lib/ludy/paginator.rb +4 -2
- data/lib/ludy/proc/curry.rb +1 -1
- data/lib/ludy/tasks/preprocess_cpp.rb +4 -2
- data/lib/ludy/tasks/preprocess_cpp/debug_hook.rb +16 -0
- data/lib/ludy/timer.rb +1 -0
- data/lib/puzzle_generator.rb +19 -3
- data/lib/puzzle_generator/map.rb +0 -4
- data/lib/puzzle_generator/misc.rb +3 -1
- data/lib/puzzle_generator/puzzle.rb +4 -1
- data/test/ludy/test_paginator.rb +8 -0
- metadata +1 -1
data/CHANGES
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
= ludy changes history
|
2
2
|
|
3
|
+
== ludy 0.1.10, 2008.02.07
|
4
|
+
|
5
|
+
* fixed an offset bug in paginator. if the offset was equal to the count,
|
6
|
+
there should be no page existed.
|
7
|
+
* fixed and updated rdoc presentation
|
8
|
+
* fixed a warning of shadowing variables in ruby 1.9
|
9
|
+
|
10
|
+
* added the offset test in test_paginator
|
11
|
+
* make some Kernel method private
|
12
|
+
|
3
13
|
== ludy 0.1.9, 2008.02.07
|
4
14
|
|
5
15
|
* fixed a bug in RailsPaginator, which ignored opts for count.
|
6
16
|
* fixed a possible bug in puzzle_generator... (not happened before?)
|
7
17
|
* fixed a stupid timeout message bug...
|
8
18
|
|
9
|
-
* added multiruby test (from ZenTest) with ruby 1.8.6-p111, 1.9.0-0, svn
|
19
|
+
* added multiruby test (from ZenTest) with ruby 1.8.6-p111, 1.9.0-0, svn trunk
|
10
20
|
* added Array#head, Array#choice!, Array#count
|
11
21
|
* added Array#product, which came from ruby 1.9 (implemented by combos in ruby 1.8)
|
12
22
|
* added Kernel#deep_copy, by Marshal idiom
|
data/README
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
= ludy 0.1.
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
http://godfat.org
|
1
|
+
= ludy 0.1.10
|
2
|
+
by Lin Jen-Shin (a.k.a. godfat-真常[http://godfat.org])
|
3
|
+
strip any number: 18god29fat7029 (at] godfat32 -dooot- 20org
|
4
|
+
* rdoc[http://ludy.rubyforge.org]
|
5
|
+
* rubyforge-project[http://rubyforge.org/projects/ludy]
|
7
6
|
|
8
7
|
== DESCRIPTION:
|
9
8
|
|
data/lib/ludy.rb
CHANGED
data/lib/ludy/array/body.rb
CHANGED
data/lib/ludy/array/combine.rb
CHANGED
@@ -2,15 +2,16 @@
|
|
2
2
|
require 'ludy/symbol/to_proc' if RUBY_VERSION < '1.9.0'
|
3
3
|
|
4
4
|
class Array
|
5
|
-
#
|
6
|
-
#
|
5
|
+
# example:
|
6
|
+
# [1,2,3].combine [2,4,6]
|
7
|
+
# => [3,6,9]
|
7
8
|
#
|
8
|
-
#
|
9
|
-
#
|
9
|
+
# [1,2].combine [1,2], [1,2]
|
10
|
+
# => [3,6]
|
10
11
|
#
|
11
|
-
#
|
12
|
-
#
|
12
|
+
# ['a','b'].combine ['b','a']
|
13
|
+
# => ['ab','ba']
|
13
14
|
def combine *target; zip(*target).map{|i|i.inject(&:+)}; end
|
14
|
-
#
|
15
|
+
# inplace version of combine
|
15
16
|
def combine! *target; replace combine(*target); end
|
16
17
|
end
|
data/lib/ludy/array/combos.rb
CHANGED
@@ -4,8 +4,8 @@ class Array
|
|
4
4
|
require 'ludy/array/foldr'
|
5
5
|
require 'ludy/symbol/to_proc' if RUBY_VERSION < '1.9.0'
|
6
6
|
# for each combos
|
7
|
-
#
|
8
|
-
#
|
7
|
+
# [[0,1],[2,3]].combos
|
8
|
+
# => [[0,2],[0,3],[1,2],[1,3]]
|
9
9
|
def combos
|
10
10
|
result = []
|
11
11
|
radixs = reverse.map(&:size)
|
@@ -22,9 +22,10 @@ class Array
|
|
22
22
|
else
|
23
23
|
require 'ludy/array/tail'
|
24
24
|
# for each combos
|
25
|
-
#
|
26
|
-
#
|
27
|
-
# simply:
|
25
|
+
# [[0,1],[2,3]].combos
|
26
|
+
# => [[0,2],[0,3],[1,2],[1,3]]
|
27
|
+
# simply:
|
28
|
+
# array.first.product *array.tail
|
28
29
|
def combos
|
29
30
|
first.product(*tail)
|
30
31
|
end
|
data/lib/ludy/array/rotate.rb
CHANGED
data/lib/ludy/array/tail.rb
CHANGED
data/lib/ludy/dices.rb
CHANGED
@@ -3,6 +3,7 @@ module Ludy
|
|
3
3
|
|
4
4
|
# dices, e.g., 4d6, 2d20, etc.
|
5
5
|
class Dices
|
6
|
+
# dices amounts of this dices; faces of this kind of dice
|
6
7
|
attr_reader :amounts, :faces
|
7
8
|
# the default dice is 1d20
|
8
9
|
def initialize amounts = 1, faces = 20
|
@@ -21,6 +22,7 @@ module Ludy
|
|
21
22
|
|
22
23
|
# a dice set could contain 4d6 + 2d20 and more dices.
|
23
24
|
class DiceSet
|
25
|
+
# the min and max possible value of this dice set.
|
24
26
|
attr_reader :min, :max
|
25
27
|
def initialize *args
|
26
28
|
@diceset = args
|
data/lib/ludy/kernel/maybe.rb
CHANGED
data/lib/ludy/paginator.rb
CHANGED
@@ -10,6 +10,7 @@ module Ludy
|
|
10
10
|
# call Page#fetch
|
11
11
|
class Page
|
12
12
|
undef_method :to_a if RUBY_VERSION < '1.9.0'
|
13
|
+
# pager to get the original pager; page to get the number of this page
|
13
14
|
attr_reader :pager, :page
|
14
15
|
# don't create a page instance yourself unless you have to
|
15
16
|
def initialize pager, page; @pager, @page = pager, page; end
|
@@ -72,7 +73,7 @@ module Ludy
|
|
72
73
|
# nil would be returned. note, page start at 1, not zero.
|
73
74
|
def page page
|
74
75
|
offset = (page-1)*@per_page
|
75
|
-
return nil unless page > 0 and offset
|
76
|
+
return nil unless page > 0 and offset < count
|
76
77
|
Page.new self, page
|
77
78
|
end
|
78
79
|
# return the amount of pages
|
@@ -93,8 +94,8 @@ module Ludy
|
|
93
94
|
# they would be used in find options. e.g.,
|
94
95
|
# RailsPaginator.new Model, :order => 'created_at DESC'
|
95
96
|
# would invoke Model.find :all, :offset => ?, :limit => ?, order => 'created_at DESC'
|
96
|
-
# TODO: conditions/options invoker...
|
97
97
|
class RailsPaginator < Paginator
|
98
|
+
# the model class that you passed in this paginator
|
98
99
|
attr_reader :model_class
|
99
100
|
def initialize model_class, opts = {}
|
100
101
|
@model_class = model_class
|
@@ -112,6 +113,7 @@ module Ludy
|
|
112
113
|
# and create pages simply for your_data[offset, per_page]
|
113
114
|
# if your data is much more complex, use Paginator instead of this
|
114
115
|
class ArrayPaginator < Paginator
|
116
|
+
# data that you passed in this paginator
|
115
117
|
attr_reader :data
|
116
118
|
def initialize data
|
117
119
|
@data = data
|
data/lib/ludy/proc/curry.rb
CHANGED
@@ -53,8 +53,10 @@ namespace :preprocess do
|
|
53
53
|
|
54
54
|
erubis_inputs.zip(erubis_outputs).each{ |input, output|
|
55
55
|
file output => input do
|
56
|
-
class ErboutEruby < Erubis::Eruby
|
57
|
-
|
56
|
+
class ErboutEruby < Erubis::Eruby #:nodoc:
|
57
|
+
include Erubis::ErboutEnhancer
|
58
|
+
end
|
59
|
+
preprocess lambda{|in_str| ErboutEruby.new in_str, :trim => false}, input, output
|
58
60
|
end
|
59
61
|
}
|
60
62
|
rescue LoadError; end # no erubis
|
@@ -2,11 +2,27 @@
|
|
2
2
|
require 'ludy/tasks/common'
|
3
3
|
|
4
4
|
module Kernel
|
5
|
+
# it simply output:
|
6
|
+
# #ifndef NDEBUG
|
7
|
+
# #include <iostream>
|
8
|
+
# #endif
|
5
9
|
def debug_include
|
6
10
|
'#ifndef NDEBUG
|
7
11
|
#include <iostream>
|
8
12
|
#endif'
|
9
13
|
end
|
14
|
+
# example usage:
|
15
|
+
# void <% debug_hook 'C::f' do %>(){
|
16
|
+
# <% end %>
|
17
|
+
# std::cout << "hello" << std::endl;
|
18
|
+
# }
|
19
|
+
# became:
|
20
|
+
# void C::f(){
|
21
|
+
# #ifndef NDEBUG
|
22
|
+
# std::cerr << "method C::f called, for " << this << " at c.cpp: 12\n"
|
23
|
+
# #endif
|
24
|
+
# std::cout << "hello" << std::endl;
|
25
|
+
# }
|
10
26
|
def debug_hook name, &block
|
11
27
|
Ludy::erbout name, block.binding
|
12
28
|
block.call
|
data/lib/ludy/timer.rb
CHANGED
data/lib/puzzle_generator.rb
CHANGED
@@ -9,15 +9,31 @@ require 'ludy/hash/reverse_merge'
|
|
9
9
|
# require 'facets/timer'
|
10
10
|
require 'ludy/timer' # simple and stupid timer....
|
11
11
|
|
12
|
+
# puzzle generator for shooting-cubes[http://shooting-cubes.googlecodes.com],
|
13
|
+
# example usage:
|
14
|
+
# PuzzleGenerator.debug = true
|
15
|
+
# pg = PuzzleGenerator::Puzzle.new :level => 4, :timeout => 2, :invoke_max => 5
|
16
|
+
# begin
|
17
|
+
# pg.generate
|
18
|
+
# pg.display_map
|
19
|
+
# rescue Ludy::Timeout => e
|
20
|
+
# puts e
|
21
|
+
# ensure
|
22
|
+
# p pg.tried_times
|
23
|
+
# p pg.tried_duration
|
24
|
+
# end
|
12
25
|
module PuzzleGenerator
|
13
26
|
|
14
|
-
def self.generate_chained_map option = {}
|
15
|
-
|
27
|
+
def self.generate_chained_map option = {} #:nodoc:
|
28
|
+
generate_klass ChainedMap, option
|
29
|
+
end
|
30
|
+
def self.generate_klass klass, option = {} #:nodoc:
|
16
31
|
option.reverse_merge! :timeout => 5
|
17
32
|
generate(option[:timeout]){ klass.new option }
|
18
33
|
end
|
19
34
|
|
20
|
-
LastTriedInfo = {}
|
35
|
+
LastTriedInfo = {} # :nodoc:
|
36
|
+
# generate someing with generator with timeout, used in Puzzle#generate
|
21
37
|
def self.generate timeout = 5, &generator
|
22
38
|
timer = Ludy::Timer.new(timeout).start
|
23
39
|
tried_times = 1
|
data/lib/puzzle_generator/map.rb
CHANGED
@@ -6,10 +6,6 @@ require 'ludy/kernel/maybe'
|
|
6
6
|
require 'ludy/array/count' if RUBY_VERSION < '1.9.0'
|
7
7
|
require 'ludy/array/product' if RUBY_VERSION < '1.9.0'
|
8
8
|
|
9
|
-
# a = [[1,2],[3,4],[5,6]]
|
10
|
-
# [a, [1,2,3]].combos
|
11
|
-
# => [[[1, 2], 1], [[1, 2], 2], [[1, 2], 3], [[3, 4], 1], [[3, 4], 2], [[3, 4], 3], [[5, 6], 1], [[5, 6], 2], [[5, 6], 3]]
|
12
|
-
|
13
9
|
module PuzzleGenerator
|
14
10
|
|
15
11
|
class Map # :nodoc:
|
@@ -3,13 +3,15 @@ require 'ludy/kernel/deep_copy'
|
|
3
3
|
require 'ludy/array/pad'
|
4
4
|
|
5
5
|
module PuzzleGenerator
|
6
|
-
Up, Right, Left = (0..2).to_a
|
6
|
+
Up, Right, Left = (0..2).to_a # :nodoc:
|
7
7
|
DefaultOption = {:width => 6, :height => 10, :level => 4, :colors => 4,
|
8
8
|
:invoke => 3, :invoke_max => 5, :timeout => 5}
|
9
9
|
# whenever the generation is falied, this exception would raise
|
10
10
|
class GenerationFailed < RuntimeError; end
|
11
11
|
class << self
|
12
|
+
# specify whether to show the answer in the puzzle
|
12
13
|
attr_writer :debug
|
14
|
+
# specify whether to show the answer in the puzzle
|
13
15
|
def debug; @debug || false; end
|
14
16
|
end
|
15
17
|
|
@@ -10,10 +10,13 @@ module PuzzleGenerator
|
|
10
10
|
class Puzzle
|
11
11
|
include DisplayMap
|
12
12
|
attr_reader :tried_times, :tried_duration
|
13
|
+
# create a puzzle with option. this won't start generating,
|
14
|
+
# call Puzzle::generate to start generating.
|
13
15
|
def initialize option = {}
|
14
16
|
@option = DefaultOption.merge option
|
15
17
|
@tried_times, @tried_duration = [0, 0], [0, 0]
|
16
18
|
end
|
19
|
+
# start generate a puzzle with options that created this puzzle instance.
|
17
20
|
def generate
|
18
21
|
raw_colors = (1..@option[:colors]).to_a
|
19
22
|
step_colors = raw_colors.rotate
|
@@ -35,7 +38,7 @@ module PuzzleGenerator
|
|
35
38
|
end
|
36
39
|
|
37
40
|
private
|
38
|
-
Chain, Color = 0, 1
|
41
|
+
Chain, Color = 0, 1 # :nodoc:
|
39
42
|
def make_chain
|
40
43
|
begin
|
41
44
|
@result_chain =
|
data/test/ludy/test_paginator.rb
CHANGED
@@ -47,6 +47,14 @@ class TestPaginator < Test::Unit::TestCase
|
|
47
47
|
})
|
48
48
|
for_pager pager
|
49
49
|
end
|
50
|
+
def test_offset_bug
|
51
|
+
a = (0..9).to_a
|
52
|
+
pager = ArrayPaginator.new a
|
53
|
+
pager.per_page = 5
|
54
|
+
assert_equal 5, pager[1].size
|
55
|
+
assert_equal 5, pager[2].size
|
56
|
+
assert_nil pager[3]
|
57
|
+
end
|
50
58
|
class Topic
|
51
59
|
class << self
|
52
60
|
def count opts = {}
|