Skip to content

Commit

Permalink
第7回のソースを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
eiel committed Dec 11, 2010
1 parent 9cbdfd9 commit c59677f
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 0 deletions.
102 changes: 102 additions & 0 deletions 07/16-file.rb
@@ -0,0 +1,102 @@
# -*- coding: utf-8 -*-

=begin
File クラス 低レベル処理がおおくあまりつかわれない?
File#remane
File.rename("before.txt","after.txt")
File.rename("data.txt","backup/data.txt")
ファイルシステム や ドライブ を越える移動はできない。
=end

# コピーする
def copy(from,to)
open(from) do |input|
open(to,"w") do |output|
output.write(input.read)
end
end
end

# fileutilsを使うと簡単
require "fileutils"

# FileUtils.cp("data","backu/data.txt")
# FileUtils.mv("data","backu/data.txt")
# FileUtirs.mkdir("goro")
# FileUtirs.mkdir_p("hoge/goro")

# ファイルの削除
# File.delete("hoge")
# File.unlink("hoge")

=begin
Dir クラス
ディレクトリの操作 -> 低レベル処理が多くあまり使われない?
=end

# 現在のディレクトリ位置を調べる
Dir.pwd # => "/Users/eiel/Documents/studying/hiroshimarb/07"
# Dir.chdir("/Users") # => 0
Dir.pwd # => "/Users/eiel/Documents/studying/hiroshimarb/07"

dir = Dir.open("/") # => #<Dir:/>
while name = dir.read
name # => ".", "..", ".dbfseventsd", ".DS_Store", ".file", ".fseventsd", ".hotfiles.btree", ".Spotlight-V100", ".Trashes", ".vol", "Applications", "bin", "cores", "dev", "Developer", "etc", "home", "id_rsa", "Library", "mach_kernel", "net", "Network", "opt", "private", "sbin", "System", "tmp", "Users", "usr", "var", "Volumes", "ユーザーズガイドと情報"
end

#Dir.chdir("/usr/share")
# Dir.glob("lib*") # => ["libiodbc", "libtool"]

# Dir.mkdir(path)
# Dir.rmdir(path)

# File.ctime("/Users") # => 2010-09-04 14:29:04 +0900
# File.chmod(0755,path)

File.exist? "/Users" # => true
File.directory? "/Users" # => true
File.writable? "/Users" # => false
File.size "/Users" # => 238

# ファイル名の操作
path = "/goro/hoge.rb"
File.basename(path) # => "hoge.rb"
File.basename(path,".rb") # => "hoge"
File.dirname(path) # => "/goro"
File.extname(path) # => ".rb"
".rb" # !> useless use of a literal in void context
File.dirname("~/hoge") # => "~"
File.expand_path("/gore/../hoge/mogu/../") # => "/hoge"

File.split(path) # => ["/goro", "hoge.rb"]
File.join("hoge","goro") # => "hoge/goro"

# ファイル操作関連のライブラリ
# find
# tempfile
# FileUtils
# Pathname

require "find"

Find.find(".") do |path| # !> shadowing outer local variable - path
path # => ".", "./.#16-file.rb", "./16-file.rb", "./16-file.rb~", "./xmptmp-in65423TmK.rb", "./xmptmp-out65423gwQ.rb"
end

require "tempfile"

tempfile = Tempfile.new("hoge")
tempfile # => #<File:/var/folders/Bz/BzpYrmcPHi01HTWPXbtDDU+++TI/-Tmp-/hoge20101204-65803-14mgbzx>
tempfile.puts("hoge")
tempfile.close
tempfile.open.read # => "hoge\n"
# tempfileは実行後に削除される

require "pathname"

path = Pathname.new("/Users")
path # => #<Pathname:/Users>
path + "hoge" # => #<Pathname:/Users/hoge>
path.entries # => [#<Pathname:.>, #<Pathname:..>, #<Pathname:.localized>, #<Pathname:eiel>, #<Pathname:Guest>, #<Pathname:PortDetect.log>, #<Pathname:Shared>]
path.children # => [#<Pathname:/Users/.localized>, #<Pathname:/Users/eiel>, #<Pathname:/Users/Guest>, #<Pathname:/Users/PortDetect.log>, #<Pathname:/Users/Shared>]
46 changes: 46 additions & 0 deletions 07/17-time.rb
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
require "time"

t = Time.new # => 2010-12-04 16:23:32 +0900
t.year # => 2010
t.month # => 12
t.day # => 4
t.hour # => 16
t.min # => 23
t.sec # => 32
t.usec # => 607788
t.to_i # => 1291447412

t = Time.mktime(2009,12,9) # => 2009-12-09 00:00:00 +0900

t1 = Time.new
t2 = Time.new
t2 - t1 # => 1.0e-06

t.strftime("%Y %m %d") # => "2009 12 09"
t.rfc2822 # => "Wed, 09 Dec 2009 00:00:00 +0900"
t.iso8601 # => "2009-12-09T00:00:00+09:00"

t.utc # => 2009-12-08 15:00:00 UTC
t.localtime # => 2009-12-09 00:00:00 +0900

t = Time.parse "2009-12-09 00:00:00 +0900" # => 2009-12-09 00:00:00 +0900
t # => 2009-12-09 00:00:00 +0900
t.class # => Time
Time.parse "s59.1.24" # => 1984-01-24 00:00:00 +0900

require "date"

d1 = Date.new(2009,12,4)
d2 = Date.new(2010,12,4)
d2 - d1 # => (365/1)
d1 + 1 # => #<Date: 2009-12-05 (4910341/2,0,2299161)>
d1 + 30 # => #<Date: 2010-01-03 (4910399/2,0,2299161)>
t + 1 # => 2009-12-09 00:00:01 +0900
t + 30 # => 2009-12-09 00:00:30 +0900
d1 >> 1 # => #<Date: 2010-01-04 (4910401/2,0,2299161)>
d1 >> 2 # => #<Date: 2010-02-04 (4910463/2,0,2299161)>

d1.strftime("%Y %m %d") # => "2009 12 04"
DateTime.parse "s59.1.24" # => #<DateTime: 1984-01-24T00:00:00+00:00 (4891447/2,0/1,2299161)>

5 changes: 5 additions & 0 deletions 07/kwartz/hoge.html
@@ -0,0 +1,5 @@
<table>
<tr class="list1">
<td class="item1">foo</td>
</tr>
</table>
10 changes: 10 additions & 0 deletions 07/kwartz/hoge.html.erb
@@ -0,0 +1,10 @@
<html>
<head>
<title></title>
</head>
<body>
<% array.each do |n| %>
<%=h n.to_s %>
<% end %>
<body>
</html>
Empty file added 07/kwartz/hoge.html.php
Empty file.
15 changes: 15 additions & 0 deletions 07/kwartz/hoge.plogic
@@ -0,0 +1,15 @@
.list1 {
logic: {
for member in @members
_stag # start tag
_cont # content
_etag # end tag
end
}
}

/* The element which is marked by 'id="mark:item1"' */
.item1 {
/* replace the content with value of a variable 'member' */
value: member;
}

0 comments on commit c59677f

Please sign in to comment.