Class: DirectoryContents
- Inherits:
-
Object
- Object
- DirectoryContents
- Defined in:
- lib/piggy-core/file_info.rb
Overview
An unordered list of FileInfos, accessible by name. The directory location is stored as a path-String.
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #[](name) ⇒ Object (also: #has_key?)
- #[]=(name, info) ⇒ Object
- #add(file_name) ⇒ Object
- #at(name) ⇒ Object
- #directories ⇒ Object
- #files ⇒ Object
- #get(file_name) ⇒ Object
-
#initialize(the_path = '') ⇒ DirectoryContents
constructor
A new instance of DirectoryContents.
- #keys ⇒ Object
Constructor Details
#initialize(the_path = '') ⇒ DirectoryContents
Returns a new instance of DirectoryContents.
149 150 151 152 |
# File 'lib/piggy-core/file_info.rb', line 149 def initialize(the_path = '') @path = the_path @contents = Hash.new end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
147 148 149 |
# File 'lib/piggy-core/file_info.rb', line 147 def path @path end |
Instance Method Details
#[](name) ⇒ Object Also known as: has_key?
170 171 172 |
# File 'lib/piggy-core/file_info.rb', line 170 def [](name) return @contents[name] end |
#[]=(name, info) ⇒ Object
158 159 160 |
# File 'lib/piggy-core/file_info.rb', line 158 def []=(name, info) @contents[name] = info end |
#add(file_name) ⇒ Object
154 155 156 |
# File 'lib/piggy-core/file_info.rb', line 154 def add(file_name) @contents[file_name.name] = file_name end |
#at(name) ⇒ Object
166 167 168 |
# File 'lib/piggy-core/file_info.rb', line 166 def at(name) return @contents[name] end |
#directories ⇒ Object
180 181 182 |
# File 'lib/piggy-core/file_info.rb', line 180 def directories return @contents.keys.select { |k| @contents[k].directory? }.sort end |
#files ⇒ Object
184 185 186 |
# File 'lib/piggy-core/file_info.rb', line 184 def files return @contents.keys.reject { |k| @contents[k].directory? }.sort end |
#get(file_name) ⇒ Object
162 163 164 |
# File 'lib/piggy-core/file_info.rb', line 162 def get(file_name) return @contents[file_name.name] end |
#keys ⇒ Object
176 177 178 |
# File 'lib/piggy-core/file_info.rb', line 176 def keys return @contents.keys end |