ykutils 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,67 @@
1
+ require 'ykutils/erubyx'
2
+
3
+ module Ykutils
4
+ module Gridlist
5
+ TAMPLETES = { :GRID_DEF =>
6
+ { :TEMPLATE => %!
7
+ .g-<%= row %>-<%= colum %> {
8
+ grid-row-start: <%= row %>;
9
+ grid-row-end: ,<%= row + 1 %>;
10
+ grid-column-start: <%= colum %>;
11
+ grid-column-end: <%= colum + 1 %>;
12
+ }
13
+ ! , :OBJ => nil } }
14
+
15
+ module_function
16
+
17
+ def make_one_grid(hash, row, colum)
18
+ unless hash[:OBJ]
19
+ hash[:OBJ] = Tilt::ErubiTemplate.new{ hash[:TEMPLATE] }
20
+ end
21
+ hash[:OBJ].render( Object.new, {row: row, colum: colum} )
22
+ end
23
+
24
+ def make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
25
+ =begin
26
+ p min_row
27
+ p max_row
28
+ p min_colum
29
+ p max_colum
30
+ =end
31
+ (min_row..max_row).map { |row|
32
+ (min_colum..max_colum).map { |colum|
33
+ #puts "#{row} #{colum}"
34
+ value_hash = { row: row, colum: colum }
35
+ #make_one_grid(template_hash, value_hash)
36
+ p template_hash
37
+ p value_hash
38
+ Ykutils::Erubyx::erubi_render(template_hash, scope, value_hash)
39
+ }
40
+ }
41
+ end
42
+
43
+ def make_grid_list()
44
+ template_hash = TAMPLETES[:GRID_DEF]
45
+ scope = nil
46
+ =begin
47
+ min_row = 1
48
+ max_row = 2
49
+ min_colum = 1
50
+ max_colum = 5
51
+ =end
52
+ make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
53
+ end
54
+
55
+ def make_grid_list_x(min_row, max_row, min_colum, max_colum)
56
+ template_hash = TAMPLETES[:GRID_DEF]
57
+ scope = nil
58
+ =begin
59
+ p min_row
60
+ p max_row
61
+ p min_colum
62
+ p max_colum
63
+ ~end
64
+ make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
65
+ end
66
+ end
67
+ end
@@ -1,25 +1,20 @@
1
1
  module Ykutils
2
2
  class Hasharray < Hash
3
-
4
- def initialize( *args )
5
- super( *args )
3
+ def initialize(*args)
4
+ super(*args)
6
5
  @ary = super.keys
7
6
  # @ary ||= []
8
- unless @ary
9
- @ary = []
10
- end
7
+ @ary ||= []
11
8
  end
12
9
 
13
- def []=(key,value)
14
- super(key,value)
15
- unless @ary.index(key)
16
- @ary << key
17
- end
10
+ def []=(key, value)
11
+ super(key, value)
12
+ @ary << key unless @ary.index(key)
18
13
  end
19
14
 
20
15
  def each(&block)
21
16
  @ary.each do |it|
22
- block.call( it, self[it] )
17
+ block.call(it, self[it])
23
18
  end
24
19
  end
25
20
 
@@ -28,7 +23,7 @@ module Ykutils
28
23
  end
29
24
 
30
25
  def values
31
- @ary.collect{ |it| self[it] }
26
+ @ary.collect { |it| self[it] }
32
27
  end
33
28
 
34
29
  def clear
@@ -36,15 +31,13 @@ module Ykutils
36
31
  @ary = []
37
32
  end
38
33
 
39
- def replace( *args )
40
- super( *args )
34
+ def replace(*args)
35
+ super(*args)
41
36
  @ary = super.keys
42
- unless @ary
43
- @ary = []
44
- end
37
+ @ary ||= []
45
38
  end
46
39
 
47
- def delete(ind , &block)
40
+ def delete(ind, &block)
48
41
  @ary.delete(ind)
49
42
 
50
43
  super
@@ -52,9 +45,7 @@ module Ykutils
52
45
 
53
46
  def delete_if(&block)
54
47
  @ary.each do |it|
55
- if block.call( it , self[it] )
56
- @ary.delete(it)
57
- end
48
+ @ary.delete(it) if block.call(it, self[it])
58
49
  end
59
50
 
60
51
  super
data/lib/ykutils/lines.rb CHANGED
@@ -1,154 +1,143 @@
1
- module Ykutils
2
- class BasicLines
3
- def initialize( line_ary )
4
- @line_ary = line_ary
5
- end
6
-
7
- def get_line
8
- if @line_ary.size > -1
9
- @line_ary.shift
10
- end
11
- end
12
- end
13
-
14
- class Lines
15
- def initialize( line_ary )
16
- @lines = BasicLines.new( line_ary )
17
- @line_stack = []
18
- @status = nil
19
-
20
- setup
21
- end
22
-
23
- def setup
24
- end
25
-
26
- def get_line
27
- if @line_stack.size > -1
28
- @line_stack.shift
29
- end
30
- end
31
-
32
- def output_f( fname )
33
- if fname
34
- File.open( fname , 'w' ){ |file|
35
- @line_stack.each do |it|
36
- file.write(it.to_s)
37
- end
38
- }
39
- end
40
- end
41
-
42
- end
43
-
44
- class FtpOpLines < BasicLines
45
- end
46
-
47
- #class AccountLines < BasicLines
48
- class AccountLines < Lines
49
- HOST_ACCOUNT_START = 10
50
- HOST_ACCOUNT = 11
51
- HOST_ACCOUNT_END = 12
52
- DOMAIN_ACCOUNT_START = 20
53
- DOMAIN_ACCOUNT = 21
54
- DOMAIN_ACCOUNT_END = 22
55
- SEPARATOR = 30
56
- ETC = 100
57
-
58
- def setup
59
- while line = @lines.get_line
60
- next if line.strip == ""
61
- if line =~ /^\-\-\-/
62
- case @status
63
- when HOST_ACCOUNT_START , HOST_ACCOUNT
64
- @line_stack.push( { "STATUS" => HOST_ACCOUNT_END ,
65
- "CONTENT" => nil })
66
- when DOMAIN_ACCOUNT_START , DOMAIN_ACCOUNT
67
- @line_stack.push( { "STATUS" => DOMAIN_ACCOUNT_END ,
68
- "CONTENT" => nil })
69
- else
70
- end
71
-
72
- @line_stack.push( { "STATUS" => SEPARATOR ,
73
- "CONTENT" => line })
74
- @status = SEPARATOR
75
-
76
- elsif line =~ /^\s/
77
- case @status
78
- when HOST_ACCOUNT_START , HOST_ACCOUNT
79
- @line_stack.push( { "STATUS" => HOST_ACCOUNT ,
80
- "CONTENT" => line })
81
- @status = HOST_ACCOUNT
82
- when HOST_ACCOUNT_END
83
- puts( "error!" )
84
- puts( line )
85
- @line_stack.push( { "STATUS" => HOST_ACCOUNT ,
86
- "CONTENT" => line })
87
- @status = HOST_ACCOUNT
88
- when DOMAIN_ACCOUNT_START , DOMAIN_ACCOUNT
89
- @line_stack.push( { "STATUS" => DOMAIN_ACCOUNT ,
90
- "CONTENT" => line })
91
- @status = DOMAIN_ACCOUNT
92
- when DOMAIN_ACCOUNT_END
93
- puts( "error!" )
94
- puts( line )
95
- @line_stack.push( { "STATUS" => DOMAIN_ACCOUNT ,
96
- "CONTENT" => line })
97
- @status = DOMAIN_ACCOUNT
98
- else
99
- @line_stack.push( { "STATUS" => ETC ,
100
- "CONTENT" => line })
101
- @status = ETC
102
- end
103
- else
104
- if line =~ /^==/
105
- case @status
106
- when HOST_ACCOUNT_START , HOST_ACCOUNT
107
- @line_stack.push( { "STATUS" => HOST_ACCOUNT_END ,
108
- "CONTENT" => nil })
109
- when DOMAIN_ACCOUNT_START , DOMAIN_ACCOUNT
110
- @line_stack.push( { "STATUS" => DOMAIN_ACCOUNT_END ,
111
- "CONTENT" => nil })
112
- else
113
- end
114
- @line_stack.push( { "STATUS" => DOMAIN_ACCOUNT_START ,
115
- "CONTENT" => line })
116
- @status = DOMAIN_ACCOUNT_START
117
- else
118
- case @status
119
- when HOST_ACCOUNT_START , HOST_ACCOUNT
120
- @line_stack.push( { "STATUS" => HOST_ACCOUNT_END ,
121
- "CONTENT" => nil })
122
- when DOMAIN_ACCOUNT_START , DOMAIN_ACCOUNT
123
- @line_stack.push( { "STATUS" => DOMAIN_ACCOUNT_END ,
124
- "CONTENT" => nil })
125
- else
126
- end
127
- @line_stack.push( { "STATUS" => HOST_ACCOUNT_START ,
128
- "CONTENT" => line })
129
- @status = HOST_ACCOUNT_START
130
- end
131
- end
132
- end
133
-
134
- i = @line_stack.size - 1
135
- seeking = true
136
- while i >= 0 and seeking
137
- case @line_stack[i]["STATUS"]
138
- when DOMAIN_ACCOUNT_START , DOMAIN_ACCOUNT
139
- @line_stack.push( { "STATUS" => DOMAIN_ACCOUNT_END ,
140
- "CONTENT" => nil })
141
- seeking = false
142
- when HOST_ACCOUNT_START , HOST_ACCOUNT
143
- @line_stack.push( { "STATUS" => HOST_ACCOUNT_END ,
144
- "CONTENT" => nil })
145
- seeking = false
146
- when ETC
147
- else
148
- seeking = false
149
- end
150
- i -= 1
151
- end
152
- end
153
- end
154
- end
1
+ module Ykutils
2
+ class BasicLines
3
+ def initialize(line_ary)
4
+ @line_ary = line_ary
5
+ end
6
+
7
+ def get_line
8
+ @line_ary.shift if @line_ary.size > -1
9
+ end
10
+ end
11
+
12
+ class Lines
13
+ def initialize(line_ary)
14
+ @lines = BasicLines.new(line_ary)
15
+ @line_stack = []
16
+ @status = nil
17
+
18
+ setup
19
+ end
20
+
21
+ def setup; end
22
+
23
+ def get_line
24
+ @line_stack.shift if @line_stack.size > -1
25
+ end
26
+
27
+ def output_f(fname)
28
+ if fname
29
+ File.open(fname, "w") do |file|
30
+ @line_stack.each do |it|
31
+ file.write(it.to_s)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ class FtpOpLines < BasicLines
39
+ end
40
+
41
+ # class AccountLines < BasicLines
42
+ class AccountLines < Lines
43
+ HOST_ACCOUNT_START = 10
44
+ HOST_ACCOUNT = 11
45
+ HOST_ACCOUNT_END = 12
46
+ DOMAIN_ACCOUNT_START = 20
47
+ DOMAIN_ACCOUNT = 21
48
+ DOMAIN_ACCOUNT_END = 22
49
+ SEPARATOR = 30
50
+ ETC = 100
51
+
52
+ def setup
53
+ while line = @lines.get_line
54
+ next if line.strip == ""
55
+
56
+ if line =~ /^---/
57
+ case @status
58
+ when HOST_ACCOUNT_START, HOST_ACCOUNT
59
+ @line_stack.push({ "STATUS" => HOST_ACCOUNT_END,
60
+ "CONTENT" => nil })
61
+ when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
62
+ @line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_END,
63
+ "CONTENT" => nil })
64
+ end
65
+
66
+ @line_stack.push({ "STATUS" => SEPARATOR,
67
+ "CONTENT" => line })
68
+ @status = SEPARATOR
69
+ elsif line =~ /^\s/
70
+ case @status
71
+ when HOST_ACCOUNT_START, HOST_ACCOUNT
72
+ @line_stack.push({ "STATUS" => HOST_ACCOUNT,
73
+ "CONTENT" => line })
74
+ @status = HOST_ACCOUNT
75
+ when HOST_ACCOUNT_END
76
+ puts("error!")
77
+ puts(line)
78
+ @line_stack.push({ "STATUS" => HOST_ACCOUNT,
79
+ "CONTENT" => line })
80
+ @status = HOST_ACCOUNT
81
+ when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
82
+ @line_stack.push({ "STATUS" => DOMAIN_ACCOUNT,
83
+ "CONTENT" => line })
84
+ @status = DOMAIN_ACCOUNT
85
+ when DOMAIN_ACCOUNT_END
86
+ puts("error!")
87
+ puts(line)
88
+ @line_stack.push({ "STATUS" => DOMAIN_ACCOUNT,
89
+ "CONTENT" => line })
90
+ @status = DOMAIN_ACCOUNT
91
+ else
92
+ @line_stack.push({ "STATUS" => ETC,
93
+ "CONTENT" => line })
94
+ @status = ETC
95
+ end
96
+ elsif line =~ /^==/
97
+ case @status
98
+ when HOST_ACCOUNT_START, HOST_ACCOUNT
99
+ @line_stack.push({ "STATUS" => HOST_ACCOUNT_END,
100
+ "CONTENT" => nil })
101
+ when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
102
+ @line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_END,
103
+ "CONTENT" => nil })
104
+ end
105
+ @line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_START,
106
+ "CONTENT" => line })
107
+ @status = DOMAIN_ACCOUNT_START
108
+ else
109
+ case @status
110
+ when HOST_ACCOUNT_START, HOST_ACCOUNT
111
+ @line_stack.push({ "STATUS" => HOST_ACCOUNT_END,
112
+ "CONTENT" => nil })
113
+ when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
114
+ @line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_END,
115
+ "CONTENT" => nil })
116
+ end
117
+ @line_stack.push({ "STATUS" => HOST_ACCOUNT_START,
118
+ "CONTENT" => line })
119
+ @status = HOST_ACCOUNT_START
120
+ end
121
+ end
122
+
123
+ i = @line_stack.size - 1
124
+ seeking = true
125
+ while i >= 0 and seeking
126
+ case @line_stack[i]["STATUS"]
127
+ when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
128
+ @line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_END,
129
+ "CONTENT" => nil })
130
+ seeking = false
131
+ when HOST_ACCOUNT_START, HOST_ACCOUNT
132
+ @line_stack.push({ "STATUS" => HOST_ACCOUNT_END,
133
+ "CONTENT" => nil })
134
+ seeking = false
135
+ when ETC
136
+ else
137
+ seeking = false
138
+ end
139
+ i -= 1
140
+ end
141
+ end
142
+ end
143
+ end
@@ -1,72 +1,71 @@
1
- require 'ykutils/filepermision'
2
- require 'pathname'
3
-
4
- module Ykytils
5
- class DirEntryItem
6
- attr_accessor :name , :user , :group , :size , :month, :day, :time , :year, :path, :type , :parent_dir , :valid
7
-
8
- def initialize
9
- end
10
-
11
- def parse( str , parent_dir , valid = true )
12
- ary = str.split(/\s+/)
13
- perm = ary[0]
14
- if perm[0].chr == 'd'
15
- @type = :DIRECTORY
16
- else
17
- @type = :FILE
18
- end
19
- @perm = FilePermision.new( ary[0][1..9] )
20
- @value = ary[1]
21
- @user = ary[2]
22
- @group = ary[3]
23
- @size = ary[4]
24
- @month = ary[5]
25
- @day = ary[6]
26
- str = ary[7]
27
- if str =~ /:/
28
- @year = Time.now.year
29
- @time = str
30
- else
31
- @year = str
32
- @time = "00:00:00"
33
- end
34
-
35
- @time = ary[7]
36
- @name = ary[8]
37
- @path = File.join( parent_dir, @name )
38
- @parent_dir = parent_dir
39
- @valid = valid
40
- end
41
-
42
- def to_hash
43
- { "type" => @type, "perm" => @perm.to_hash, "value" => @value, "user" => @user , "group" => @group, "size" => @size, "month" => @month, "day" => @day, "year" => @year , "time" => @time, "name" => @name, "path" => @path, "parent_dir" => @parent_dir , "valid" => @valid }
44
- end
45
-
46
- def to_csv
47
- "#{@type},#{@perm.to_s},#{@value},#{@user},#{@group},#{@size},#{@year},#{@month},#{@day},#{@time},#{@name},#{@parent_dir},#{@valid}"
48
- end
49
-
50
- def directory?
51
- @type === :DIRECTORY
52
- end
53
-
54
- def file?
55
- @type === :FILE
56
- end
57
-
58
- def owner_perm
59
- @perm.owner
60
- end
61
-
62
- def group_perm
63
- @perm.group
64
- end
65
-
66
- def otherr_perm
67
- @perm.other
68
- end
69
- end
70
-
71
-
72
- end
1
+ require "ykutils/filepermision"
2
+ require "pathname"
3
+
4
+ module Ykytils
5
+ class DirEntryItem
6
+ attr_accessor :name, :user, :group, :size, :month, :day, :time, :year, :path, :type, :parent_dir, :valid
7
+
8
+ def initialize; end
9
+
10
+ def parse(str, parent_dir, valid = true)
11
+ ary = str.split(/\s+/)
12
+ perm = ary[0]
13
+ @type = if perm[0].chr == "d"
14
+ :DIRECTORY
15
+ else
16
+ :FILE
17
+ end
18
+ @perm = FilePermision.new(ary[0][1..9])
19
+ @value = ary[1]
20
+ @user = ary[2]
21
+ @group = ary[3]
22
+ @size = ary[4]
23
+ @month = ary[5]
24
+ @day = ary[6]
25
+ str = ary[7]
26
+ if str =~ /:/
27
+ @year = Time.now.year
28
+ @time = str
29
+ else
30
+ @year = str
31
+ @time = "00:00:00"
32
+ end
33
+
34
+ @time = ary[7]
35
+ @name = ary[8]
36
+ @path = File.join(parent_dir, @name)
37
+ @parent_dir = parent_dir
38
+ @valid = valid
39
+ end
40
+
41
+ def to_hash
42
+ { "type" => @type, "perm" => @perm.to_hash, "value" => @value, "user" => @user, "group" => @group,
43
+ "size" => @size, "month" => @month, "day" => @day, "year" => @year,
44
+ "time" => @time, "name" => @name, "path" => @path, "parent_dir" => @parent_dir, "valid" => @valid }
45
+ end
46
+
47
+ def to_csv
48
+ "#{@type},#{@perm},#{@value},#{@user},#{@group},#{@size},#{@year},#{@month},#{@day},#{@time},#{@name},#{@parent_dir},#{@valid}"
49
+ end
50
+
51
+ def directory?
52
+ @type === :DIRECTORY
53
+ end
54
+
55
+ def file?
56
+ @type === :FILE
57
+ end
58
+
59
+ def owner_perm
60
+ @perm.owner
61
+ end
62
+
63
+ def group_perm
64
+ @perm.group
65
+ end
66
+
67
+ def otherr_perm
68
+ @perm.other
69
+ end
70
+ end
71
+ end