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.
154 155 156 157 |
# File 'lib/piggy-core/file_info.rb', line 154 def initialize(the_path = '') @path = the_path @contents = Hash.new end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
152 153 154 |
# File 'lib/piggy-core/file_info.rb', line 152 def path @path end |
Instance Method Details
#[](name) ⇒ Object Also known as: has_key?
175 176 177 |
# File 'lib/piggy-core/file_info.rb', line 175 def [](name) return @contents[name] end |
#[]=(name, info) ⇒ Object
163 164 165 |
# File 'lib/piggy-core/file_info.rb', line 163 def []=(name, info) @contents[name] = info end |
#add(file_name) ⇒ Object
159 160 161 |
# File 'lib/piggy-core/file_info.rb', line 159 def add(file_name) @contents[file_name.name] = file_name end |
#at(name) ⇒ Object
171 172 173 |
# File 'lib/piggy-core/file_info.rb', line 171 def at(name) return @contents[name] end |
#directories ⇒ Object
185 186 187 |
# File 'lib/piggy-core/file_info.rb', line 185 def directories return @contents.keys.select { |k| @contents[k].directory? }.sort end |
#files ⇒ Object
189 190 191 |
# File 'lib/piggy-core/file_info.rb', line 189 def files return @contents.keys.reject { |k| @contents[k].directory? }.sort end |
#get(file_name) ⇒ Object
167 168 169 |
# File 'lib/piggy-core/file_info.rb', line 167 def get(file_name) return @contents[file_name.name] end |
#keys ⇒ Object
181 182 183 |
# File 'lib/piggy-core/file_info.rb', line 181 def keys return @contents.keys end |