gitlab.com/evatix-go/core@v1.3.55/coredata/corerange/StartEndSimpleString.go (about)

     1  package corerange
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"gitlab.com/evatix-go/core/constants"
     7  	"gitlab.com/evatix-go/core/coredata/corestr"
     8  )
     9  
    10  type StartEndSimpleString struct {
    11  	Start string `json:"Start"`
    12  	End   string `json:"End"`
    13  }
    14  
    15  func (it *StartEndSimpleString) IsInvalidStart() bool {
    16  	return it == nil || it.Start == ""
    17  }
    18  
    19  func (it *StartEndSimpleString) IsStartEndBothDefined() bool {
    20  	return it != nil && it.HasStart() && it.HasEnd()
    21  }
    22  
    23  func (it *StartEndSimpleString) IsInvalidStartEndBoth() bool {
    24  	return it.IsInvalidStart() && it.IsInvalidEnd()
    25  }
    26  
    27  func (it *StartEndSimpleString) IsInvalidAnyStartEnd() bool {
    28  	return it.IsInvalidStart() || it.IsInvalidEnd()
    29  }
    30  
    31  func (it *StartEndSimpleString) StartValidValue() *corestr.ValidValue {
    32  	if it == nil {
    33  		return nil
    34  	}
    35  
    36  	return corestr.NewValidValue(it.Start)
    37  }
    38  
    39  func (it *StartEndSimpleString) EndValidValue() *corestr.ValidValue {
    40  	if it == nil {
    41  		return nil
    42  	}
    43  
    44  	return corestr.NewValidValue(it.End)
    45  }
    46  
    47  func (it *StartEndSimpleString) StartEndString() *StartEndString {
    48  	if it == nil {
    49  		return nil
    50  	}
    51  
    52  	hasStart := it.HasStart()
    53  	hasEnd := it.HasEnd()
    54  
    55  	return &StartEndString{
    56  		BaseRange: &BaseRange{
    57  			RawInput:  it.StringHyphen(),
    58  			Separator: constants.Hyphen,
    59  			IsValid:   hasStart == hasEnd && hasStart == true,
    60  			HasStart:  hasEnd,
    61  			HasEnd:    hasStart,
    62  		},
    63  		Start: it.Start,
    64  		End:   it.End,
    65  	}
    66  }
    67  
    68  func (it *StartEndSimpleString) HasStart() bool {
    69  	return it != nil && it.Start != ""
    70  }
    71  
    72  func (it *StartEndSimpleString) IsInvalidEnd() bool {
    73  	return it == nil || it.End == ""
    74  }
    75  
    76  func (it *StartEndSimpleString) HasEnd() bool {
    77  	return it != nil && it.End != ""
    78  }
    79  
    80  func (it *StartEndSimpleString) StringUsingFormat(format string) string {
    81  	return fmt.Sprintf(format, it.Start, it.End)
    82  }
    83  
    84  func (it *StartEndSimpleString) StringSpace() string {
    85  	return fmt.Sprintf("%s %s", it.Start, it.End)
    86  }
    87  
    88  func (it *StartEndSimpleString) StringHyphen() string {
    89  	return fmt.Sprintf("%s-%s", it.Start, it.End)
    90  }
    91  
    92  func (it *StartEndSimpleString) StringColon() string {
    93  	return fmt.Sprintf("%s:%s", it.Start, it.End)
    94  }
    95  
    96  func (it *StartEndSimpleString) RangeInt(minMax *MinMaxInt) *RangeInt {
    97  	return NewRangeInt(
    98  		it.StringColon(),
    99  		constants.Colon,
   100  		minMax)
   101  }
   102  
   103  func (it *StartEndSimpleString) RangeInt16(minMax *MinMaxInt16) *RangeInt16 {
   104  	return NewRangeInt16(it.StringColon(), constants.Colon, minMax)
   105  }
   106  
   107  func (it *StartEndSimpleString) RangeInt8(minMax *MinMaxInt8) *RangeInt8 {
   108  	return NewRangeInt8(
   109  		it.StringColon(),
   110  		constants.Colon,
   111  		minMax)
   112  }