Module: FeduxOrgStdlib::Roles::Typable
- Defined in:
- lib/fedux_org_stdlib/roles/typable.rb
Overview
Typable
If need to determine the file type of a object, you can include ‘FeduxOrgStdlib::Roles::Typeable`. You only need to define a method `source_path`, which is used by the included methods. It needs to return a `Pathname`.
Instance Method Summary collapse
-
#extnames ⇒ Object
Return extensions.
-
#extnames?(*exts) ⇒ Boolean
Has file extensions.
-
#file? ⇒ Boolean
Is file?.
-
#font? ⇒ Boolean
Is font?.
-
#image? ⇒ Boolean
Is image?.
-
#script? ⇒ Boolean
Is script?.
- #source_path ⇒ Object
-
#stylesheet? ⇒ Boolean
Is stylesheet?.
-
#type ⇒ Object
Determine type of object.
-
#type?(t) ⇒ true, false
Check on file type.
-
#valid? ⇒ true, false
Is it a valid.
Instance Method Details
#extnames ⇒ Object
Return extensions
83 84 85 |
# File 'lib/fedux_org_stdlib/roles/typable.rb', line 83 def extnames source_path.basename.to_s.scan(/(\.[^.]+)/).flatten end |
#extnames?(*exts) ⇒ Boolean
Has file extensions
78 79 80 |
# File 'lib/fedux_org_stdlib/roles/typable.rb', line 78 def extnames?(*exts) !(extnames & exts.flatten).empty? end |
#file? ⇒ Boolean
Is file?
63 64 65 |
# File 'lib/fedux_org_stdlib/roles/typable.rb', line 63 def file? source_path.file? end |
#font? ⇒ Boolean
Is font?
128 129 130 |
# File 'lib/fedux_org_stdlib/roles/typable.rb', line 128 def font? font_by_path? || font_by_extension? end |
#image? ⇒ Boolean
Is image?
88 89 90 |
# File 'lib/fedux_org_stdlib/roles/typable.rb', line 88 def image? image_by_path? || (image_by_extension? && !font_by_path?) end |
#script? ⇒ Boolean
Is script?
147 148 149 |
# File 'lib/fedux_org_stdlib/roles/typable.rb', line 147 def script? script_by_path? || script_by_extension? end |
#source_path ⇒ Object
35 36 37 |
# File 'lib/fedux_org_stdlib/roles/typable.rb', line 35 def source_path fail NoMethodError, :source_path end |
#stylesheet? ⇒ Boolean
Is stylesheet?
108 109 110 |
# File 'lib/fedux_org_stdlib/roles/typable.rb', line 108 def stylesheet? stylesheet_by_path? || stylesheet_by_extension? end |
#type ⇒ Object
Determine type of object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fedux_org_stdlib/roles/typable.rb', line 48 def type @type ||= if image? :image elsif script? :script elsif stylesheet? :stylesheet elsif font? :font else :unknown end end |
#type?(t) ⇒ true, false
Check on file type
43 44 45 |
# File 'lib/fedux_org_stdlib/roles/typable.rb', line 43 def type?(t) type == t end |
#valid? ⇒ true, false
Is it a valid
70 71 72 |
# File 'lib/fedux_org_stdlib/roles/typable.rb', line 70 def valid? file? end |