Class: Skit::JsonSchema::ClassNamePath
- Inherits:
-
Object
- Object
- Skit::JsonSchema::ClassNamePath
- Extended by:
- T::Sig
- Defined in:
- lib/skit/json_schema/class_name_path.rb
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Class Method Summary collapse
Instance Method Summary collapse
- #append(suffix) ⇒ Object
-
#initialize(parts) ⇒ ClassNamePath
constructor
A new instance of ClassNamePath.
- #parent_class ⇒ Object
- #property_name ⇒ Object
- #to_class_name ⇒ Object
Constructor Details
#initialize(parts) ⇒ ClassNamePath
Returns a new instance of ClassNamePath.
10 11 12 |
# File 'lib/skit/json_schema/class_name_path.rb', line 10 def initialize(parts) @parts = T.let(parts.dup, T::Array[String]) end |
Instance Attribute Details
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
41 42 43 |
# File 'lib/skit/json_schema/class_name_path.rb', line 41 def parts @parts end |
Class Method Details
.default ⇒ Object
36 37 38 |
# File 'lib/skit/json_schema/class_name_path.rb', line 36 def self.default ClassNamePath.new(["GeneratedClass"]) end |
.from_file_path(file_path) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/skit/json_schema/class_name_path.rb', line 28 def self.from_file_path(file_path) return default unless file_path basename = File.basename(file_path, ".*") ClassNamePath.new([NamingUtils.to_pascal_case(basename)]) end |
.title_to_class_name(title) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/skit/json_schema/class_name_path.rb', line 15 def self.title_to_class_name(title) # Split existing PascalCase before conversion (APIResponseData -> API_Response_Data) with_underscores = title.gsub(/([a-z])([A-Z])/, '\1_\2') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') class_name = NamingUtils.to_pascal_case(with_underscores) return default if class_name.empty? ClassNamePath.new([class_name]) end |
Instance Method Details
#append(suffix) ⇒ Object
44 45 46 |
# File 'lib/skit/json_schema/class_name_path.rb', line 44 def append(suffix) ClassNamePath.new(@parts + [NamingUtils.to_pascal_case(suffix)]) end |
#parent_class ⇒ Object
49 50 51 52 53 |
# File 'lib/skit/json_schema/class_name_path.rb', line 49 def parent_class return nil if @parts.length < 2 @parts[0] end |
#property_name ⇒ Object
56 57 58 |
# File 'lib/skit/json_schema/class_name_path.rb', line 56 def property_name T.must(@parts.last) end |
#to_class_name ⇒ Object
61 62 63 64 |
# File 'lib/skit/json_schema/class_name_path.rb', line 61 def to_class_name # Generate class name by converting each part to PascalCase (TestUser + address -> TestUserAddress) @parts.join end |